Skip to content
Richard Wallis edited this page Aug 7, 2014 · 6 revisions

Inject Analytics into the class you want to track events from.

@Inject
MyConstructor(Analytics analytics) {
  this.analytics = analytics;
}

REMEMBER TO CALL go()

Analytics uses a version of the builder pattern where you call the type of tracking method you want, then chain the options you need to the call followed by go().

###Tracking Page Views

analytics.sendPageView().go(); //track a pageview
analytics.sendPageView().documentPath("/foo").go(); //track a pageview for page /foo

###Tracking events

analytics.sendEvent("button", "click").eventLabel("my label").go(); //send event with label
analytics.sendEvent("category", "action").eventLabel("label").hitOptions().nonInteractionHit(true).go(); //send an event not instigated by the user.

###Changing Global Settings If you want to change the global settings call setGlobalSettings after your create().go() call.

analytics.setGlobalSettings().anonymizeIp(true).go(); //anonymize ips
Clone this wiki locally