Esri / hub.js

TypeScript wrappers for talking to ArcGIS Hub
https://esri.github.io/hub.js/
Apache License 2.0
33 stars 13 forks source link

@esri/telemetry integration #76

Open tomwayson opened 6 years ago

tomwayson commented 6 years ago

Call https://www.npmjs.com/package/@esri/telemetry .logEvent() if an instance of Telemetry is provided.

This probably makes the most sense after #75 since we'll probably want something like this:

import Hub from '@esri/hub';
import Telemetry from '@esri/telemetry';

const telemetryConfig = { /* base telemetry config here */ };
const hubConfig = { orgId : 'awefa', telemetry: { /* hub specific telemetry config here */ } };
const hub = new Hub(hubConfig);
hub.teletmetry = new Telemetry(telemetryConfig);
hub.signIn()
.then(() => {
  hub.getInitative('3ef'`); // calls hub.telemtry.logEvent() after calling @esri/hub-initative getInitiative()
});

The hub specific telemetry config might map hub.js packages/functions to categories/actions.

Also, having it as a property would expose telemetry to so that the app can use it for non-hub specific things like:

// after transitioning to a route
hub.telemetry.logPageView(options);
tomwayson commented 6 years ago

Another option is that we could also add a telemetry: ITelemetryProvider option the stateless fn's that would act like authentication. If that option is truthy and exposes a logEvent() fn, then tack on a call to logEvent() after the current request.

This would move the actual logging down a level to the stateless fns. In the above scenario, the Hub() instance would just pass in the telemetry to the stateless fns (just like authentication) instead of calling logEvent() directly.

Where that starts to unravel is that is we'd also need a logEventOptions: ILogEventOptions option passed into the request unless we didn't allow the category, etc, to be configurable at the app level. In otherwords, getInitiative('3ef') would always log w/:

{ 
  category: '@esri/hub-initatives',
  action: 'getInitative',
  label: 'Initative Title', // pull this from the getItem response
  initativeId: '3ef', // is this even possible? I see datasetID in the examples
  user: 'amazing_map_woman' // pull this from the authentication request option
}

TBH, that works for me, and I suppose we could also always add the logEventOptions later if somebody really needed their events logged w/ specific categories/actions.

tomwayson commented 6 years ago

I'm not sure if we need to support workflows - @dbouwman would that be used by the coarse-grained initiative API?

tomwayson commented 6 years ago

Also, of course, we don't need to integrate w/ telemetry at this level. We could just include an example that shows how consumers could call logEvent() themselves in any of our stateless fns' .then() block.

dbouwman commented 6 years ago

@tomwayson I would lean very heavily towards having telemetry in the consuming application, not directly within this library.

I think we can easily create demo code that shows how to send telemetry to your own GA account, via the the progress callbacks in coarse-grained calls. Way better than tight coupling to telemetry.js imho