auth0/auth0-metrics

Name: auth0-metrics

Owner: Auth0

Description: Frontend tracking with Segment and custom server

Created: 2015-07-31 15:03:15.0

Updated: 2017-04-05 06:36:11.0

Pushed: 2017-12-21 16:09:15.0

Homepage: null

Size: 2379

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

auth0-metrics

This library provides a module to track all frontend usage on auth0.com, it wraps Segment and sends the same data both to segment and our own endpoint. When defining new metrics, please revise the methodology at the data playbook.

Installation

To install the dependencies, execute:

npm install

Usage (local)

To build and run the library locally, you can run npm run dev, that will let you include the library from http://localhost:9999/auth0-metrics.js, you can also test the methods included in http://localhost:9999/

Usage (deploy)
CDN

Using our CDN is the preferred solution. Just add the following line in your project's HTML head and you are done.

ipt src="https://cdn.auth0.com/js/m/1.5.0/auth0-metrics.min.js"></script>

Then you have to call the constructor with the correct dev/prod variables

metrics = new Auth0Metrics('segmentKey', 'dwhEndpoint', 'website');
Loader

A script that will asynchronously load auth0-metrics.js is also provided.

ipt src="auth0-metrics-loader.js"></script>
ipt>
tricsLib.load({
segmentKey: 'segmentKey',
dwhEndpoint: 'dwhEndpoint',
label: 'website'
;
ript>

Once loaded, an instance of Auth0Metrics will be available on metricsLib. Calls to public instance methods of Auth0Metrics on metricsLib will be silently ignored until then.

racks the page if auth0-metrics.js has been loaded, otherwise the call is
gnored and doesn't produce an error.
icsLib.page();

If auth0-metrics.js has already been loaded, the script will not attempt load it again, and will simply create an instance of Auth0Metrics with the given configuration.

Using the loader may also be desired when loading auth0-metrics.js synchronously. If there's an exception during the instantiation of Auth0Metrics, the stubs methods will still be in place and calls like the one above to page won't throw.

ipt src="auth0-metrics.js"></script>
ipt src="auth0-metrics-loader.js"></script>
ipt>
tricsLib.load({
segmentKey: 'segmentKey',
dwhEndpoint: 'dwhEndpoint',
label: 'website'
;
ript>

Contrast the previous snippet with the following that instantiates Auth0Metrics directly.

ipt src="auth0-metrics.js"></script>
ipt>
r metricsLib = new Auth0Metrics('segmentKey', 'dwhEndpoint', 'website');
ript>

If the instantiation doesn't succeed, trying to call a method on metricsLib will throw because it is undefined and may break the behavior of your site.

API
.setUserId(uid)

Sets the userId of the currently connected client

Parameters
.page(callback)

Sends information of the current page to track it

Parameters
.track(event, data, callback)

Sends information of a custom event to track.

Parameters
.identify(id, traits, callback)

Sends information of an identification (login/signup) to track.

NOTE: This method's signature does not fully pair with Segment's analytics.js. You can proxy directly to Segment by doing metricsLib.segment().identify() instead.

Parameters

You can omit the user id if you want to associate traits with the currently identified user, anonymous or not. You can also omit traits if all you want to do is associate an id. Finally, callback is optional and can always be omitted.

.alias(id, callback)

Sends an alias (renaming a previous id to a new one).

Parameters
.traits()

Traits (additional properties) of the current user

.ready(cb)

Executes a callback when segment finishes loading.

Parameters
Issue Reporting

If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.

Author

Auth0

License

This project is licensed under the MIT license. See the LICENSE file for more info.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.