-
Notifications
You must be signed in to change notification settings - Fork 126
First telemetry API draft #187
First telemetry API draft #187
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking good, thanks for doing this. few architectural questions.
and per my dailies, I plan to revisit this by EOW. but if we want analytics ASAP this will probably suffice.
<script src="%UNITY_WEBGL_LOADER_URL%"></script> | ||
<script src="src/telemetry.js"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this feels more like lib/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any Telemetry code should happen before the Unity Engine is loaded. it's quite possible that there are errors that get thrown which could affect the loading of that and/or this script.
either way, the code should be run before the Unity JS. so we can get accurate perf timings, catch network errors, runtime errors, etc. either it should be a blocking <script>
above or an inline <script>
.
@@ -76,8 +83,8 @@ <h3>You’ll need a <a href="https://webvr.rocks/">WebVR-enabled browser</a> | |||
<button id="entervr" value="Enter VR"></button> | |||
</div> | |||
|
|||
<script src="gl-matrix-min.js"></script> | |||
<script src="webvr-polyfill.min.js"></script> | |||
<script src="lib/gl-matrix-min.js"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be called vendor/
return; | ||
} | ||
|
||
var navigator = window.navigator; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is unnecessary; just use navigator
directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we plan to test in the future, this is more convenient, don't you think?
'use strict'; | ||
|
||
if (!('UnityLoader' in window)) { | ||
console.warn('`UnityLoader` object not found.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not found
-> not be found
setupAnalytics(); | ||
|
||
function setupAnalytics() { | ||
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is copied from GA's snippet builder, but might as well just unminify this
return script; | ||
} | ||
|
||
function getModule (modulePath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe I'm missing the purpose: why we're using this as opposed to just calling the object directly?
<script src="%UNITY_WEBGL_LOADER_URL%"></script> | ||
<script src="src/telemetry.js"></script> | ||
<script> | ||
UnityLoader.WebVR.telemetry.start({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the invocation and naming of this. good work! 👍
although I'm not keen on this being attached to the UnityLoader
for the aforementioned reasons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you! looks good - let's get this merged but not released/deployed yet without the opt-out text instructions (per filed issues)
CSS changes may be better made in a separate PR
} | ||
|
||
if (!('telemetry' in window.MozillaResearch)) { | ||
window.MozillaResearch.telemetry = {} ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trailing whitespace
Makes sense. I'm going to undo the changes to CSS, remove the trailing whitespace and get it merged. |
Fix #172
Fix #169
The PR adds some folder structure to the template and proposes an API for telemetry, Roughly, the telemetry module installs itself inside the
UnityLoader
object atUnityLoader.WebVR.telemtry
. This way, there is only one entry point for everything.To configure and start telemetry, the developer calls
telemetry.start(config)
and passes aconfig
object with two properties so far granting permissions for Mozilla Research to log errors and gather analytics:If the developer wants to add their custom tracker, they should use
MozillaResearch.telemetry.ga.create()
with the same signature as thecreate
command of GA. The library then returns a function that can be treated like the regularga()
function. The pattern is inspired by @cvan proposal but provides more flexibility for the end user.