Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit a0588f0

Browse files
committed
Addressing issues.
1 parent c8ae386 commit a0588f0

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

Assets/WebGLTemplates/WebVR/lib/telemetry.js

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121

2222
var CURRENT_VERSION = '1.0.2';
23+
var MOZILLA_RESEARCH_TRACKER = 'UA-77033033-6';
2324

2425
if (!('MozillaResearch' in window)) {
2526
window.MozillaResearch = {};
@@ -34,11 +35,6 @@ var telemetry = window.MozillaResearch.telemetry;
3435

3536
var NO_OP = function () {};
3637

37-
// Always returns what is in `window[GA_ALIAS]`. According to:
38-
// https://developers.google.com/analytics/devguides/collection/analyticsjs/how-analyticsjs-works
39-
// The `analytics.js` script will redefine the `window[GA_ALIAS]` function after
40-
// loading. Accessing the function indirectly ensures we always get the most
41-
// recent implementation of it.
4238
Object.defineProperty(telemetry, '_gtag', {
4339
get: function () {
4440
return window.gtag || NO_OP;
@@ -72,7 +68,7 @@ function setupAnalytics() {
7268
window.gtag = window.gtag || function () { dataLayer.push(arguments); };
7369
window.gtag('js', new Date());
7470

75-
injectScript('https://www.googletagmanager.com/gtag/js?id=UA-77033033-6', function (err) {
71+
injectScript('https://www.googletagmanager.com/gtag/js?id=' + MOZILLA_RESEARCH_TRACKER, function (err) {
7672
if (err) {
7773
console.warn('Could not load Analytics.js script:', err);
7874
return;
@@ -97,12 +93,12 @@ function setupErrorLogging() {
9793

9894
function startRaven () {
9995
Raven.config('https://e359be9fb9324addb0dc97b664cf5ee6@sentry.io/294878')
100-
.install();
96+
.install();
10197
}
10298
};
10399

104100
function startAnalytics() {
105-
var tracker = newTracker('UA-77033033-6', {
101+
var tracker = configureBoundTracker(MOZILLA_RESEARCH_TRACKER, {
106102
'groups': 'MozillaResearch',
107103
'custom_map': {
108104
'dimension1': 'version'
@@ -134,11 +130,22 @@ function setupPerformanceAPI(tracker) {
134130
};
135131
}
136132

137-
// Provides a convenient shortcut for named trackers by automatically adding the
138-
// name of the tracker to the command. The function accepts the same parameters
139-
// that follow `create` command. See:
140-
// https://developers.google.com/analytics/devguides/collection/analyticsjs/creating-trackers
141-
function newTracker(trackingId, options) {
133+
/**
134+
* The function configures Google Analytics sending a `config` command [1] but
135+
* also returns a function to use instead of `gtag` that respects `Do-Not-Track`
136+
* and it's bound to the `groups` property of the `options` parameter to avoid
137+
* adding the `send_to` key [2] to each command.
138+
*
139+
* [1] https://developers.google.com/analytics/devguides/collection/gtagjs/pages
140+
* [2] https://developers.google.com/analytics/devguides/collection/gtagjs/sending-data#groups-and-properties
141+
*
142+
* @param {string} trackingId see `'config'` command signature [1]
143+
* @param {onject} options see `'config'` command signature [1]
144+
* @returns {function} A tracker function to replace invocation of `gtag` that
145+
* honours Do-Not-Track and automatically adds the `send_to` key to the
146+
* commands [2].
147+
*/
148+
function configureBoundTracker(trackingId, options) {
142149
if (doNotTrack()) { return NO_OP; }
143150

144151
options = options || {};
@@ -180,8 +187,8 @@ function injectScript(src, callback) {
180187
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/doNotTrack#Browser_compatibility
181188
function doNotTrack() {
182189
return navigator.doNotTrack === '1' ||
183-
navigator.msDoNotTrack === '1' ||
184-
window.doNotTrack === '1';
190+
navigator.msDoNotTrack === '1' ||
191+
window.doNotTrack === '1';
185192
}
186193

187-
})(window);
194+
})(window);

docs/customization/adding-ga.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This will redirect you to the configuration page where you find the HTML code yo
2424

2525
Copy and paste this code as the first item into the `<head>` tag.
2626

27-
Read [sending data to Google Analytics](https://developers.google.com/analytics/devguides/collection/gtagjs/sending-data?hl=es) to learn how to use the `gtag` API.
27+
Read [Google Analytics' "Sending Data" documentation](https://developers.google.com/analytics/devguides/collection/gtagjs/sending-data?hl=es) to learn how to use the `gtag` API.
2828

2929
## Using Google Analytics
3030

0 commit comments

Comments
 (0)