Skip to content

Commit

Permalink
Read userId from cookie, only set on GA if user non anonymous
Browse files Browse the repository at this point in the history
  • Loading branch information
pierreavizou committed May 4, 2020
1 parent 039242e commit 101367f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/rudder-analytics.min.js

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions integrations/GA/browser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import logger from "../../utils/logUtil";
import { Cookie } from "../../utils/storage/cookie";

class GA {
constructor(config) {
this.trackingID = config.trackingID;
Expand Down Expand Up @@ -33,20 +35,21 @@ class GA {
ga("create", this.trackingID, "auto", "rudder_ga", {
allowLinker: this.allowLinker,
});

var userId = Cookie.get('rl_user_id');
if (userId && userId !== '') {
ga("rudder_ga.set", "userId", userId);
}
//ga("send", "pageview");

logger.debug("===in init GA===");
}

setUserId(rudderElement) {
identify(rudderElement) {
var userId = rudderElement.message.userId !== ''
? rudderElement.message.userId
: rudderElement.message.anonymousId
ga("rudder_ga.set", "userId", userId);
}

identify(rudderElement) {
this.setUserId(rudderElement);
logger.debug("in GoogleAnalyticsManager identify");
}

Expand Down Expand Up @@ -74,7 +77,6 @@ class GA {
eventLabel: eventLabel,
eventValue: eventValue
};
this.setUserId(rudderElement);
ga("rudder_ga.send", "event", payLoad);
logger.debug("in GoogleAnalyticsManager track");
}
Expand Down Expand Up @@ -103,7 +105,6 @@ class GA {
if (location) {
ga("rudder_ga.set", "location", location);
}
this.setUserId(rudderElement);
ga("rudder_ga.send", "pageview");

}
Expand Down

0 comments on commit 101367f

Please sign in to comment.