From 42efd33cfa7c09bdc25a99276a32ff465e9d8880 Mon Sep 17 00:00:00 2001 From: Renzo Lucioni Date: Mon, 1 Jul 2013 15:56:01 -0400 Subject: [PATCH] Refactor Segment.io integration with sequentials and instructor dashboard pages --- .../xmodule/js/src/sequence/display.coffee | 26 +++++++++++++++++++ common/static/coffee/spec/logger_spec.coffee | 10 ------- common/static/coffee/src/logger.coffee | 12 --------- .../src/instructor_dashboard_tracking.coffee | 4 +++ .../courseware/instructor_dashboard.html | 2 +- lms/templates/widgets/segment-io.html | 3 ++- 6 files changed, 33 insertions(+), 24 deletions(-) create mode 100644 lms/static/coffee/src/instructor_dashboard_tracking.coffee diff --git a/common/lib/xmodule/xmodule/js/src/sequence/display.coffee b/common/lib/xmodule/xmodule/js/src/sequence/display.coffee index 0e4c9788ba..1892ef7d6f 100644 --- a/common/lib/xmodule/xmodule/js/src/sequence/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/sequence/display.coffee @@ -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) -> diff --git a/common/static/coffee/spec/logger_spec.coffee b/common/static/coffee/spec/logger_spec.coffee index 4a53b8c455..e8f174665d 100644 --- a/common/static/coffee/spec/logger_spec.coffee +++ b/common/static/coffee/spec/logger_spec.coffee @@ -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' diff --git a/common/static/coffee/src/logger.coffee b/common/static/coffee/src/logger.coffee index dffc14e067..0c60dc8f7a 100644 --- a/common/static/coffee/src/logger.coffee +++ b/common/static/coffee/src/logger.coffee @@ -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 diff --git a/lms/static/coffee/src/instructor_dashboard_tracking.coffee b/lms/static/coffee/src/instructor_dashboard_tracking.coffee new file mode 100644 index 0000000000..a4eab610c8 --- /dev/null +++ b/lms/static/coffee/src/instructor_dashboard_tracking.coffee @@ -0,0 +1,4 @@ +if $('.instructor-dashboard-wrapper').length == 1 + analytics.track "Loaded an Instructor Dashboard Page", + location: window.location.pathname + dashboard_page: $('.navbar .selectedmode').text() diff --git a/lms/templates/courseware/instructor_dashboard.html b/lms/templates/courseware/instructor_dashboard.html index bc49cda427..f5abe3476d 100644 --- a/lms/templates/courseware/instructor_dashboard.html +++ b/lms/templates/courseware/instructor_dashboard.html @@ -104,7 +104,7 @@ function goto( mode)

Instructor Dashboard

-

[ Grades | +