Refactor Segment.io integration with sequentials and instructor dashboard pages
This commit is contained in:
@@ -111,6 +111,14 @@ class @Sequence
|
||||
if (1 <= new_position) and (new_position <= @num_contents)
|
||||
Logger.log "seq_goto", old: @position, new: new_position, id: @id
|
||||
|
||||
analytics.pageview @id
|
||||
|
||||
# navigation by clicking the tab directly
|
||||
analytics.track "Accessed Sequential Directly",
|
||||
sequence_id: @id
|
||||
current_sequential: @position
|
||||
target_sequential: new_position
|
||||
|
||||
# On Sequence chage, destroy any existing polling thread
|
||||
# for queued submissions, see ../capa/display.coffee
|
||||
if window.queuePollerID
|
||||
@@ -125,12 +133,30 @@ class @Sequence
|
||||
event.preventDefault()
|
||||
new_position = @position + 1
|
||||
Logger.log "seq_next", old: @position, new: new_position, id: @id
|
||||
|
||||
analytics.pageview @id
|
||||
|
||||
# navigation using the next arrow
|
||||
analytics.track "Accessed Next Sequential",
|
||||
sequence_id: @id
|
||||
current_sequential: @position
|
||||
target_sequential: new_position
|
||||
|
||||
@render new_position
|
||||
|
||||
previous: (event) =>
|
||||
event.preventDefault()
|
||||
new_position = @position - 1
|
||||
Logger.log "seq_prev", old: @position, new: new_position, id: @id
|
||||
|
||||
analytics.pageview @id
|
||||
|
||||
# navigation using the previous arrow
|
||||
analytics.track "Accessed Previous Sequential",
|
||||
sequence_id: @id
|
||||
current_sequential: @position
|
||||
target_sequential: new_position
|
||||
|
||||
@render new_position
|
||||
|
||||
link_for: (position) ->
|
||||
|
||||
@@ -3,16 +3,6 @@ describe 'Logger', ->
|
||||
expect(window.log_event).toBe Logger.log
|
||||
|
||||
describe 'log', ->
|
||||
it 'sends an event to Segment.io, if the event is whitelisted and the data is not a dictionary', ->
|
||||
spyOn(analytics, 'track')
|
||||
Logger.log 'seq_goto', 'data'
|
||||
expect(analytics.track).toHaveBeenCalledWith 'seq_goto', value: 'data'
|
||||
|
||||
it 'sends an event to Segment.io, if the event is whitelisted and the data is a dictionary', ->
|
||||
spyOn(analytics, 'track')
|
||||
Logger.log 'seq_goto', value: 'data'
|
||||
expect(analytics.track).toHaveBeenCalledWith 'seq_goto', value: 'data'
|
||||
|
||||
it 'send a request to log event', ->
|
||||
spyOn $, 'postWithPrefix'
|
||||
Logger.log 'example', 'data'
|
||||
|
||||
@@ -1,19 +1,8 @@
|
||||
class @Logger
|
||||
|
||||
# events we want sent to Segment.io for tracking
|
||||
SEGMENT_IO_WHITELIST = ["seq_goto", "seq_next", "seq_prev", "problem_check", "problem_reset", "problem_show", "problem_save"]
|
||||
|
||||
# listeners[event_type][element] -> list of callbacks
|
||||
listeners = {}
|
||||
@log: (event_type, data, element = null) ->
|
||||
# Segment.io event tracking
|
||||
if event_type in SEGMENT_IO_WHITELIST
|
||||
# to avoid changing the format of data sent to our servers, we only massage it here
|
||||
if typeof data isnt 'object' or data is null
|
||||
analytics.track event_type, value: data
|
||||
else
|
||||
analytics.track event_type, data
|
||||
|
||||
# Check to see if we're listening for the event type.
|
||||
if event_type of listeners
|
||||
# Cool. Do the elements also match?
|
||||
@@ -43,7 +32,6 @@ class @Logger
|
||||
else
|
||||
listeners[event_type][element].push callback
|
||||
|
||||
|
||||
@bind: ->
|
||||
window.onunload = ->
|
||||
$.ajaxWithPrefix
|
||||
|
||||
Reference in New Issue
Block a user