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

Commit 53993c4

Browse files
committed
First draft of telemetry interface
1 parent 2249e7b commit 53993c4

File tree

2 files changed

+91
-21
lines changed

2 files changed

+91
-21
lines changed

Assets/WebGLTemplates/WebVR/index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@
1111
<meta name="description" content="%UNITY_CUSTOM_DESCRIPTION%">
1212
<link rel="icon" href="favicon.ico">
1313
<link rel="stylesheet" type="text/css" href="styles/webvr.css">
14-
<script src="src/telemetry.js"></script>
1514
<script src="%UNITY_WEBGL_LOADER_URL%"></script>
15+
<script src="src/telemetry.js"></script>
16+
<script>
17+
UnityLoader.WebVR.telemetry.start({
18+
researchAnalytics: true,
19+
researchErrorLogging: true
20+
});
21+
</script>
1622
<script>
1723
/* global UnityLoader */
1824
(function () {
Lines changed: 84 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,82 @@
11
/* global localStorage, location, Raven */
2-
(function () {
3-
// This checks for "production"-looking origins (e.g., `https://example.com`).
4-
if (window.isSecureContext === false ||
5-
(location.hostname === 'localhost' ||
6-
location.hostname === '127.0.0.1' ||
7-
location.hostname === '0.0.0.0' ||
8-
location.hostname.indexOf('ngrok.io') > -1 ||
9-
location.hostname.indexOf('localtunnel.me') > -1)) {
2+
(function (window) {
3+
'use strict';
4+
5+
if (!('UnityLoader' in window)) {
6+
console.warn('`UnityLoader` object not found.');
107
return;
118
}
129

13-
injectScript('https://cdn.ravenjs.com/3.22.3/console/raven.min.js', function (err) {
14-
if (err) {
15-
console.warn('Could not load Raven.js script:', err);
10+
var navigator = window.navigator;
11+
var telemetry = getModule('UnityLoader.WebVR.telemetry');
12+
13+
telemetry.ga = {
14+
create: function (trackingId, cookieDomain, name, fieldsObject) {
15+
window.ga('create', trackingId, cookieDomain, name, fieldsObject);
16+
return function (command) {
17+
if (navigator.doNotTrack === '1') { return; }
18+
var args = Array.prototype.slice.call(arguments);
19+
if (name && command !== 'provide') {
20+
command = name + '.' + command;
21+
args[0] = command;
22+
}
23+
window.ga.apply(undefined, args);
24+
};
25+
}
26+
};
27+
28+
telemetry.start = function (config) {
29+
if (navigator.doNotTrack === '1') {
1630
return;
1731
}
18-
if (!('Raven' in window)) {
19-
console.warn('Could not find `window.Raven` global');
32+
if (config.researchErrorLogging) {
33+
startErrorLogging();
34+
}
35+
if (config.researchAnalytics) {
36+
startAnalytics();
37+
}
38+
};
39+
40+
setupAnalytics();
41+
42+
function setupAnalytics() {
43+
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
44+
if (navigator.doNotTrack === '1') {
2045
return;
2146
}
22-
ravenLoaded();
23-
});
47+
injectScript('https://www.google-analytics.com/analytics.js', function (err) {
48+
if (err) {
49+
console.warn('Could not load Analytics.js script:', err);
50+
return;
51+
}
52+
});
53+
}
2454

25-
function ravenLoaded () {
26-
console.log('Raven.js script loaded');
27-
Raven.config('https://e359be9fb9324addb0dc97b664cf5ee6@sentry.io/294878')
28-
.install();
55+
function startErrorLogging() {
56+
injectScript('https://cdn.ravenjs.com/3.22.3/console/raven.min.js', function (err) {
57+
if (err) {
58+
console.warn('Could not load Raven.js script:', err);
59+
return;
60+
}
61+
if (!('Raven' in window)) {
62+
console.warn('Could not find `window.Raven` global');
63+
return;
64+
}
65+
configureRaven();
66+
});
67+
68+
function configureRaven () {
69+
console.log('Raven.js script loaded');
70+
Raven.config('https://e359be9fb9324addb0dc97b664cf5ee6@sentry.io/294878')
71+
.install();
72+
}
73+
};
74+
75+
function startAnalytics() {
76+
var CURRENT_VERSION = '1.0.1';
77+
var ga = telemetry.ga.create('UA-77033033-6', 'auto', 'mozillaResearch');
78+
ga('set', 'dimension1', CURRENT_VERSION);
79+
ga('send', 'pageview');
2980
}
3081

3182
function injectScript (src, callback) {
@@ -45,4 +96,17 @@ function injectScript (src, callback) {
4596
document.head.appendChild(script);
4697
return script;
4798
}
48-
})();
99+
100+
function getModule (modulePath) {
101+
var fragments = modulePath.split('.');
102+
var currentModule = window;
103+
for (var i = 0, l = fragments.length; i < l; i++) {
104+
var submoduleName = fragments[i];
105+
if (!(submoduleName in currentModule)) {
106+
currentModule[submoduleName] = {};
107+
}
108+
currentModule = currentModule[submoduleName];
109+
}
110+
return currentModule;
111+
}
112+
})(window);

0 commit comments

Comments
 (0)