Skip to content

Commit

Permalink
add page prop to context and autotrack enabled as option
Browse files Browse the repository at this point in the history
  • Loading branch information
sayan-rudder committed Mar 17, 2020
1 parent c00027d commit b28cb38
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ class Analytics {
try {
logger.debug("===in process response=== " + status);
response = JSON.parse(response);
if (response.source.useAutoTracking) {
if (
response.source.useAutoTracking &&
!this.autoTrackHandlersRegistered
) {
this.autoTrackFeatureEnabled = true;
addDomEventHandlers(this);
this.autoTrackHandlersRegistered = true;
Expand Down Expand Up @@ -122,6 +125,7 @@ class Analytics {
);
if (this.autoTrackFeatureEnabled && !this.autoTrackHandlersRegistered) {
addDomEventHandlers(this);
this.autoTrackHandlersRegistered = true;
}
}
}
Expand Down Expand Up @@ -521,10 +525,14 @@ class Analytics {
this.setAnonymousId();
}

// assign page properties to context
rudderElement["message"]["context"]["page"] = getDefaultPageProperties();

rudderElement["message"]["context"]["traits"] = Object.assign(
{},
this.userTraits
);

logger.debug("anonymousId: ", this.anonymousId);
rudderElement["message"]["anonymousId"] = this.anonymousId;
rudderElement["message"]["userId"] = rudderElement["message"]["userId"]
Expand Down Expand Up @@ -665,6 +673,17 @@ class Analytics {
if (options && options.configUrl) {
configUrl = options.configUrl;
}
if (options && options.useAutoTracking) {
this.autoTrackFeatureEnabled = true;
if (this.autoTrackFeatureEnabled && !this.autoTrackHandlersRegistered) {
addDomEventHandlers(this);
this.autoTrackHandlersRegistered = true;
logger.debug(
"autoTrackHandlersRegistered",
this.autoTrackHandlersRegistered
);
}
}
if (
options &&
options.valTrackingList &&
Expand Down

0 comments on commit b28cb38

Please sign in to comment.