Skip to content

Commit

Permalink
Merge pull request #22 from activeprospect/time-on-page
Browse files Browse the repository at this point in the history
Added time_on_page_in_seconds to response variables
  • Loading branch information
alexkwolfe committed Feb 26, 2015
2 parents 518b4a6 + 0286527 commit 9399a80
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions spec/claim_spec.coffee
Expand Up @@ -289,6 +289,14 @@ describe 'Claim Response', ->
response = getResponse(body, vars)
assert.equal response.age_in_seconds, 172353 # 172291s + 61.999s


it 'time on page included when event duration present', ->
vars = {}
body = event_duration: 61999
response = getResponse(body, vars)
assert.equal response.time_on_page_in_seconds, 62 # 61.999s rounded


it 'returns an error when cert not found', ->
res =
status: 404
Expand Down Expand Up @@ -398,6 +406,7 @@ expected = (vars = {}) ->
url: vars.url || null
domain: vars.domain || "localhost"
age_in_seconds: 172291
time_on_page_in_seconds: null
created_at: "2014-04-02T21:24:22Z"
scans:
found: []
Expand Down
7 changes: 7 additions & 0 deletions src/claim.coffee
Expand Up @@ -69,6 +69,11 @@ ageInSeconds = (claim) ->
Math.round difference / 1000


timeOnPageInSeconds = (event_duration) ->
return null if !event_duration? or isNaN(event_duration)
Math.round parseInt(event_duration) / 1000


formatScanReason = (scannedFor, textArray) ->
matches = textArray.filter (t) ->
scannedFor.indexOf(t) >= 0
Expand Down Expand Up @@ -103,6 +108,7 @@ response = (vars, req, res) ->
url: hosted_url
domain: url.parse(hosted_url).hostname if hosted_url?
age_in_seconds: ageInSeconds event
time_on_page_in_seconds: timeOnPageInSeconds event.event_duration
created_at: event.cert.created_at
scans:
found: event.scans?.found || []
Expand Down Expand Up @@ -146,6 +152,7 @@ response.variables = ->
{ name: 'url', type: 'string', description: 'Parent frames URL if the page is framed, or location of the page hosting the javascript' }
{ name: 'domain', type: 'string', description: 'Domain of the url' }
{ name: 'age_in_seconds', type: 'number', description: 'Number of seconds since the certificate was created' }
{ name: 'time_on_page_in_seconds', type: 'number', description: 'Number of seconds the consumer spent filling out the offer form' }
{ name: 'created_at', type: 'time', description: 'Time the user loaded the form in UTC ISO8601 format' }
{ name: 'masked', type: 'boolean', description: 'Whether the cert being claimed is masked'}
{ name: 'scans.found', type: 'array', description: 'Forbidden scan terms found in the claim'}
Expand Down

0 comments on commit 9399a80

Please sign in to comment.