Google Analytics

The Google Analytics integration is a bi-directional integration that enables the automatic tracking of events from Google Analytics to Taplytics and the ability to push Experiment and Feature Flag data from Taplytics back into Google Analytics.


Google Analytics to Taplytics

The Google Analytics integration allows you to leverage the same client-side events being sent from your App for Goal Creation on the Taplytics platform. These events will automatically flow into Taplytics and will be visible in the Code Event dropdown. For more information on goal creation, please see here.

Android

Google Analytics 7.0.0-
If you are using Google Analytics 7.0.0 and below, all Google Analytics will automatically be sent to both Google Analytics and Taplytics.

Google Analytics 7.3.0+
If you are using Google Analytics 7.3.0 or above, you'll need make some changes in code to send your Google Analytics Events to both Google and Taplytics.

Simply find all instances of tracker.send(new Hitbuilder...) and replace them with Taplytics.logGAEvent(tracker, new Hitbuilder...)

You can do this with a simple find/replace in your application.

Example:

Tracker t = TrackerManager.getInstance().getGoogleAnalyticsTracker(TrackerManager.TrackerName.APP_TRACKER, getApplication());
t.send(new HitBuilders.EventBuilder()
                      .setCategory("someCategory")
                      .setAction("someAction")
                      .setLabel("someLabel")
                      .setValue(12)
                      .build());
val t: Tracker = TrackerManager.getInstance()
  .getGoogleAnalyticsTracker(
    TrackerManager.TrackerName.APP_TRACKER,
    com.apple.eawt.Application.getApplication()
  )
t.send(
  EventBuilder()
    .setCategory("someCategory")
    .setAction("someAction")
    .setLabel("someLabel")
    .setValue(12)
    .build()
)

The above would be replaced with:

Tracker t = TrackerManager.getInstance()
                          .getGoogleAnalyticsTracker(TrackerManager.TrackerName.APP_TRACKER, getApplication());
Taplytics.logGAEvent(t, new HitBuilders.EventBuilder()
                                       .setCategory("someCategory")
                                       .setAction("someAction")
                                       .setLabel("someLabel")
                                       .setValue(12)
                                       .build());
val t: Tracker = TrackerManager.getInstance()
  .getGoogleAnalyticsTracker(
    TrackerManager.TrackerName.APP_TRACKER,
    com.apple.eawt.Application.getApplication()
  )
Taplytics.logGAEvent(
  t, EventBuilder()
    .setCategory("someCategory")
    .setAction("someAction")
    .setLabel("someLabel")
    .setValue(12)
    .build()
)

Taplytics to Google Analytics

The Taplytics SDK can automatically push Experiment and Feature Flag data back to your Google Analytics instance so that you may continue reporting on your desired analytics platform.

To enable this feature, turn on the Google Analytics toggle in the Push Experiments to Analytics Sources section located at the bottom of the Settings page and add start options if necessary.

Android

To enable the Taplytics Android SDK to send experiment/variation data to Google Analytics, the tracker instance must be passed as a start options to Taplytics.

HashMap<String, Object> options = new HashMap<>();
options.put("gaTracker", tracker);
Taplytics.startTaplytics(this, "YOUR_SDK_KEY", options);
val options: HashMap<String, Any> = HashMap()
options["gaTracker"] = tracker
Taplytics.startTaplytics(this, "YOUR_SDK_KEY", options)

Taplytics logs experiment/variation events to the Google Analytics Android SDK as follows:

HashMap<String, String> experimentsAndVariations = new HashMap<>();
experimentsAndVariations.put("Experiment 1", "Variation 1");
experimentsAndVariations.put("Experiment 2", "Variation 3");

for (String experiment : experimentsAndVariations.keySet()) {
    googleTracker.set(experiment,experimentsAndVariations.get(experiment));
}

iOS

Taplytics logs experiment/variation events to the Google Analytics iOS SDK as follows:

id<GAITracker> tracker = [GAI sharedInstance].defaultTracker;
NSDictionary* experimentsAndVariations = @{
    @"Experiment 1": @"Variation 1",
    @"Experiment 2": @"baseline"
};
for (NSString* experimentName in experimentsAndVariations.allKeys) {
    NSString* variationName = experimentsAndVariations[experimentName];
    [tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"TL_experiments"
                                           action:experimentName
                                            label:variationName
                                            value:nil] build]];
}
weak var tracker = GAI.sharedInstance().defaultTracker
let experimentsAndVariations = [
    "Experiment 1": "Variation 1",
    "Experiment 2": "baseline"
]
for experimentName in experimentsAndVariations.keys {
    let variationName = experimentsAndVariations[experimentName]
    tracker?.send(GAIDictionaryBuilder.createEvent(withCategory: "TL_experiments", action: experimentName, label: variationName, value: nil).build())
}

Web

On version 2.26.0 or above of the Taplytics JS SDK, Taplytics will send experiment/variation data to Google Analytics as an event called Taplytics Experiment Viewed with the data attached to the event.

eventData = {"Experiment 1": "Variation 1", "Experiment 2": "baseline", ...}

Object.keys(eventData).forEach((expName) => {
    ga('send', {
        hitType: 'event',
        eventAction: 'Taplytics Experiment Viewed',
        eventCategory: expName,
        eventLabel: eventData[expName]
    })
})

Did this page help you?