Commit 87f52a84 by Mike Dikan Committed by mikedikan

Send identify events to Segment before page events from ecommerce

ECOM-6650

Calling the logging of the user to segment before calling the tracking function, so events are attributed to the correct user.
parent 91af552f
......@@ -486,6 +486,8 @@ define([
});
it('should trigger page load analytics event', function() {
$('<script type="text/javascript">var initModelData = {"course": {"courseId": "a/b/c"}};</script>')
.appendTo('body');
AnalyticsUtils.analyticsSetUp();
expect(window.analytics.page).toHaveBeenCalled();
});
......
......@@ -42,6 +42,7 @@ define([
// kick off segment
this.initSegment(trackId);
this.logUser();
this.recordPageData();
// now segment has been loaded, we can track events
this.listenTo(this.model, 'segment:track', this.track);
......@@ -49,13 +50,12 @@ define([
},
/**
* This sets up Segment for our application and loads the initial
* page load.
* This sets up Segment for our application
*
* this.segment is set for convenience.
*/
initSegment: function (applicationKey) {
var analytics, pageData;
var analytics;
/* jshint ignore:start */
// jscs:disable
......@@ -65,20 +65,19 @@ define([
// provide our application key for logging
analytics.load(applicationKey);
pageData = this.getSegmentPageData();
analytics.page(pageData);
},
/**
* Get data for initializing segment.
* Get data for initializing segment and record the initial page load.
*/
getSegmentPageData: function () {
recordPageData: function () {
var pageData = {};
if (this.options.courseModel.get('courseId')) {
return this.buildCourseProperties();
pageData = this.buildCourseProperties();
}
return {};
analytics.page(pageData);
},
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment