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

First telemetry API draft #187

Merged
merged 4 commits into from
Mar 6, 2018
Merged

First telemetry API draft #187

merged 4 commits into from
Mar 6, 2018

Conversation

delapuente
Copy link
Contributor

@delapuente delapuente commented Mar 2, 2018

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 at UnityLoader.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 a config object with two properties so far granting permissions for Mozilla Research to log errors and gather analytics:

MozillaResearch.telemetry.start({
  analytics: true,
  errorLogging: true        
});

If the developer wants to add their custom tracker, they should use MozillaResearch.telemetry.ga.create() with the same signature as the create command of GA. The library then returns a function that can be treated like the regular ga() function. The pattern is inspired by @cvan proposal but provides more flexibility for the end user.

@delapuente delapuente requested a review from cvan March 2, 2018 12:55
@delapuente delapuente added this to the Telemetry milestone Mar 2, 2018
@delapuente delapuente changed the title Issue 169 add opt out ga First telemetry API draft Mar 2, 2018
Copy link
Contributor

@cvan cvan left a 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>
Copy link
Contributor

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/

Copy link
Contributor

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&rsquo;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>
Copy link
Contributor

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;
Copy link
Contributor

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

Copy link
Contributor Author

@delapuente delapuente Mar 5, 2018

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.');
Copy link
Contributor

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;
Copy link
Contributor

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) {
Copy link
Contributor

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({
Copy link
Contributor

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.

Copy link
Contributor

@cvan cvan left a 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 = {} ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing whitespace

@delapuente
Copy link
Contributor Author

Makes sense. I'm going to undo the changes to CSS, remove the trailing whitespace and get it merged.

@delapuente delapuente merged commit cc6f8a4 into MozillaReality:master Mar 6, 2018
delapuente added a commit that referenced this pull request Mar 6, 2018
…-ga"

This reverts commit cc6f8a4, reversing
changes made to 285ab2f.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants