Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

Commit

Permalink
Added User ID tracking to the Google Analytics MasterPageTracker
Browse files Browse the repository at this point in the history
  • Loading branch information
Rvthof committed Aug 7, 2015
1 parent d8aa4d2 commit 4c74d0d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
13 changes: 13 additions & 0 deletions src/GoogleAnalytics/MasterPageTracker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@
<caption>Active</caption>
<category>Behavior</category>
<description>Enable/disable tracking</description>
</property>
<property key="useridAttr" type="attribute" required="false" allowNonPersistableEntities="true" isPath="optional" pathType="reference">
<caption>User ID attribute</caption>
<category>Data source</category>
<description>The value of this attribute will be used to uniquely identify the user in your Google Analytics.</description>
<attributeTypes>
<attributeType name="String" />
</attributeTypes>
</property>
<property key="userIdDimension" type="integer" defaultValue="0">
<caption>User ID dimension</caption>
<category>Data source</category>
<description>This value will be used to map the user to a custom dimension in your Google Analytics.</description>
</property>
<property key="attributeList" type="object" isList="true" required="false">
<caption>Attributes</caption>
Expand Down
21 changes: 15 additions & 6 deletions src/GoogleAnalytics/widget/MasterPageTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ define("GoogleAnalytics/widget/MasterPageTracker", [
// Declare widget"s prototype.
return declare("GoogleAnalytics.widget.MasterPageTracker", [_WidgetBase], {

// Parameters configured in the Modeler.
mfToExecute: "",
messageString: "",
backgroundColor: "",

// Internal variables. Non-primitives created in the prototype are shared between all widget instances.
_handles: null,
_contextObj: null,
Expand Down Expand Up @@ -107,7 +102,21 @@ define("GoogleAnalytics/widget/MasterPageTracker", [

if (typeof window.mxGoogleAnalytics === "undefined") {
this._replaceTags(this.uaTrackCode, lang.hitch(this, function (text) {
ga('create', text, 'auto');
var opts = { 'cookieDomain': 'auto' };

if (this.useridAttr != '') {
var uid = this._contextObj.get(this.useridAttr);
opts.userId = uid;
ga('create', text, opts);
ga('set', '&uid', uid);

if (this.userIdDimension > 0)
ga('set', 'dimension'+this.userIdDimension, uid);

} else {
ga('create', text, opts);
}

}));
}
},
Expand Down
Binary file modified test/Test.mpr
Binary file not shown.
Binary file modified test/widgets/GoogleAnalytics.mpk
Binary file not shown.

0 comments on commit 4c74d0d

Please sign in to comment.