Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #588 from edx/thallada/nav-tracking-fixes
Browse files Browse the repository at this point in the history
Navigation tracking fixes
  • Loading branch information
thallada authored Dec 2, 2016
2 parents e983f4f + f941b90 commit 054f5d7
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 4 deletions.
94 changes: 94 additions & 0 deletions analytics_dashboard/static/js/test/specs/tracking-view-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,5 +362,99 @@ define(['jquery', 'models/course-model', 'models/tracking-model', 'models/user-m
test.showTooltip();
test.expectNoEventToHaveBeenEmitted();
});

it('should transform target HTML data attributes', function() {
var test = setupTest();

test.sandbox.attr('data-track-target-scope', 'course');
test.sandbox.attr('data-track-target-lens', 'mylens');
test.sandbox.attr('data-track-target-report', 'myreport');
test.sandbox.attr('data-track-target-depth', 'mydepth');
test.showTooltip();

test.expectEventEmitted(
'trackingEvent', {
label: 'course_mylens_myreport',
courseId: 'my/course/id',
org: 'org',
param: 'my-param',
foo: 'bar',
current_page: {
scope: 'course',
lens: 'mylens',
report: 'myreport',
depth: '',
name: 'course_mylens_myreport'
},
target_page: {
scope: 'course',
lens: 'mylens',
report: 'myreport',
depth: 'mydepth',
name: 'course_mylens_myreport_mydepth'
}
}
);
});

it('should transform target HTML data attributes (with name parts missing)', function() {
var test = setupTest();

test.sandbox.attr('data-track-target-scope', 'course');
test.sandbox.attr('data-track-target-lens', 'mylens');
test.showTooltip();

test.expectEventEmitted(
'trackingEvent', {
label: 'course_mylens_myreport',
courseId: 'my/course/id',
org: 'org',
param: 'my-param',
foo: 'bar',
current_page: {
scope: 'course',
lens: 'mylens',
report: 'myreport',
depth: '',
name: 'course_mylens_myreport'
},
target_page: {
scope: 'course',
lens: 'mylens',
report: '',
depth: '',
name: 'course_mylens'
}
}
);
});

it('should transform link-name and menu-depth HTML data attributes', function() {
var test = setupTest();

test.sandbox.attr('data-track-menu-depth', 'lens');
test.sandbox.attr('data-track-link-name', 'mylens');
test.showTooltip();

test.expectEventEmitted(
'trackingEvent', {
label: 'course_mylens_myreport',
courseId: 'my/course/id',
org: 'org',
param: 'my-param',
foo: 'bar',
current_page: {
scope: 'course',
lens: 'mylens',
report: 'myreport',
depth: '',
name: 'course_mylens_myreport'
},
menu_depth: 'lens',
link_name: 'mylens',
category: 'lens+mylens'
}
);
});
});
});
10 changes: 6 additions & 4 deletions analytics_dashboard/static/js/views/tracking-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,16 @@ define(['backbone', 'jquery', 'underscore', 'utils/utils'],
transformPropertiesFromHTMLAttributes: function(props) {
var properties = props,
targetNameParts = [],
parts = ['scope', 'lens', 'report', 'depth'];
parts = ['scope', 'lens', 'report', 'depth'],
partVal;
// collapse target scope, lens, report, and depth to a target_page dict
if ('target-scope' in properties) {
properties.target_page = {};
parts.forEach(function(part) {
properties.target_page[part] = properties['target-' + part] || '';
if (part !== '' && part !== undefined) {
targetNameParts.push(part);
partVal = properties['target-' + part] || '';
properties.target_page[part] = partVal;
if (partVal !== '' && partVal !== undefined) {
targetNameParts.push(partVal);
}
delete properties['target-' + part];
});
Expand Down

0 comments on commit 054f5d7

Please sign in to comment.