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

Commit 4c74d0d

Browse files
committed
Added User ID tracking to the Google Analytics MasterPageTracker
1 parent d8aa4d2 commit 4c74d0d

4 files changed

Lines changed: 28 additions & 6 deletions

File tree

src/GoogleAnalytics/MasterPageTracker.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@
3333
<caption>Active</caption>
3434
<category>Behavior</category>
3535
<description>Enable/disable tracking</description>
36+
</property>
37+
<property key="useridAttr" type="attribute" required="false" allowNonPersistableEntities="true" isPath="optional" pathType="reference">
38+
<caption>User ID attribute</caption>
39+
<category>Data source</category>
40+
<description>The value of this attribute will be used to uniquely identify the user in your Google Analytics.</description>
41+
<attributeTypes>
42+
<attributeType name="String" />
43+
</attributeTypes>
44+
</property>
45+
<property key="userIdDimension" type="integer" defaultValue="0">
46+
<caption>User ID dimension</caption>
47+
<category>Data source</category>
48+
<description>This value will be used to map the user to a custom dimension in your Google Analytics.</description>
3649
</property>
3750
<property key="attributeList" type="object" isList="true" required="false">
3851
<caption>Attributes</caption>

src/GoogleAnalytics/widget/MasterPageTracker.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ define("GoogleAnalytics/widget/MasterPageTracker", [
2626
// Declare widget"s prototype.
2727
return declare("GoogleAnalytics.widget.MasterPageTracker", [_WidgetBase], {
2828

29-
// Parameters configured in the Modeler.
30-
mfToExecute: "",
31-
messageString: "",
32-
backgroundColor: "",
33-
3429
// Internal variables. Non-primitives created in the prototype are shared between all widget instances.
3530
_handles: null,
3631
_contextObj: null,
@@ -107,7 +102,21 @@ define("GoogleAnalytics/widget/MasterPageTracker", [
107102

108103
if (typeof window.mxGoogleAnalytics === "undefined") {
109104
this._replaceTags(this.uaTrackCode, lang.hitch(this, function (text) {
110-
ga('create', text, 'auto');
105+
var opts = { 'cookieDomain': 'auto' };
106+
107+
if (this.useridAttr != '') {
108+
var uid = this._contextObj.get(this.useridAttr);
109+
opts.userId = uid;
110+
ga('create', text, opts);
111+
ga('set', '&uid', uid);
112+
113+
if (this.userIdDimension > 0)
114+
ga('set', 'dimension'+this.userIdDimension, uid);
115+
116+
} else {
117+
ga('create', text, opts);
118+
}
119+
111120
}));
112121
}
113122
},

test/Test.mpr

0 Bytes
Binary file not shown.

test/widgets/GoogleAnalytics.mpk

167 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)