Google Tag Manager (GTM) bridge

Setup the Accengage Bridge for GTM

  1. Create (or use an existing) Firebase account.
  2. Go to the Google Tag Management (GTM) console.
  3. Create a GTM account - if you already have one, please go to step 4

    • Indicate an account name.
    • Select a country.
  4. Create your container:

    • Indicate its name.
    • Select your platform.
    • Choose the SDK version: Firebase.

Img

  1. Add the GTM dependency 

    • In your module Gradle file (usually app/build.gradle), add the following dependency on the Tag Manager library:
dependencies {//...     
  compile 'com.google.android.gms:play-services-tagmanager:11.0.4}


  1. Add method “getContext” in your Application class

    • Add this code in your Application class for the Accengage bridge to be able to use your application context
private static Context sContext;
 
@Override
public void onCreate() {
  super.onCreate();
  sContext = getApplicationContext();
}
 
public static Context getContext() {
  return sContext;
}
  1. Add Accengage’s bridge.

  2. Go back to the GTM interface.
  3. Submit your container changes and publish the container or create a version.
  4. Download your container version.
  5. Create the app/src/main/assets/containers folder if it doesn't exist. Copy the downloaded container to the folder.
  6. Preview your container. To be able to test your GTM modification before publishing, add “preview activity” to your Android Manifest.

    • Add this preview activity to your AndroidManifest file:
<activity 
android:name="com.google.android.gms.tagmanager.TagManagerPreviewActivity"
android:noHistory="true"> <!-- optional, removes the previewActivity from the activity stack.-->
    <intent-filter>
        <data android:scheme="tagmanager.c.yourpackagename" />
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
    </intent-filter>
</activity>

Change this line to include your application's package name:

<data android:scheme="tagmanager.c.yourpackagename" />
  1. Generate a link in the GTM console for the preview.

You’ll find in the Google Tag Manager documentation more information about this preview feature.

Your Application is now well configured to trigger the Accengage SDK methods on Firebase events. After that, you'll need to setup your tags on GTM interface.

Accengage action key

The Accengage GTM bridge has to be used with a key acc_action to define what action you want Accengage to do with your parameters. That key acc_action should be used with one of the following values :

  • track_event
  • track_lead
  • track_add_to_cart
  • track_purchase
  • set_udi
  • delete_udi
  • increment_udi
  • decrement_udi

As our tracking methods have some mandatory parameters, some methods will need some specific keys to work.

Create a Trigger

Want to know more about what is a GTM trigger? please follow this link GTM Tags are fired on triggers. Then you'll need to create triggers to send Accengage SDK actions. The conditions of your trigger depend on when you want the Accengage SDK action to be sent. We recommend to use the Event Name that is already tagged in your application, but you can use whatever you want.

Create a Tag

Want to know more about what is a GTM tag? please follow this link

GTM Tags are fired on triggers. Then you'll need to create triggers to send Accengage SDK actions. The conditions of your trigger depends on when you want the Accengage SDK action to be sent. We recommand to use the Event Name that is already tagged in your application but you can use your own.

TrackEvent

  1. Create a new Tag.
  2. Add a previously created trigger: AccengageTrackEventTrigger in that case.
  3. Set the tag type with Function Call.
  4. Indicate the classpath of the Accengage bridge in your application: ACCCustomTagProvider.
  5. Add the acc_action key and fill the value with the Accengage SDK action you want to do. In that case, track_event.
  6. Then add the acc_event_id key with your event ID as a value.
  7. You can also add some personal key/value. All of them will be added as parameters in the Accengage trackEvent method.

Img

TrackLead

  1. Create a new Tag.
  2. Add a previously created trigger: AccengageTrackLeadTrigger in that case.
  3. Set the tag type with Function Call.
  4. Indicate the classpath of the Accengage bridge in your application: ACCCustomTagProvider.
  5. Add the acc_action key and fill the value with the Accengage SDK action you want to do. In that case, track_lead.
  6. Then add the two mandatory keys of a Lead, acc_lead_label, and acc_lead_value.
  7. Fill them with the appropriate values or variables.

Img

TrackAddToCart

  1. Create a new Tag.
  2. Add a previously created trigger : AccengageTrackAddToCartTrigger in that case
  3. Set the tag type with Function Call
  4. Indicate the classpath of the Accengage bridge in your application: ACCCustomTagProvider
  5. Add the acc_action key and fill the value with the Accengage SDK action you want to do. In that case, track_add_to_cart.
  6. Then add the mandatory keys for an Add To Cart, acc_cart_idacc_item_idacc_item_labelacc_item_categoryacc_item_currencyacc_item_price and acc_item_quantity.
  7. Fill them with the appropriate values or variables.

Img

TrackPurchase

  1. Create a new Tag.
  2. Add a previously created trigger: AccengageTrackPurchaseTrigger in that case
  3. Set the tag type with Function Call
  4. Indicate the classpath of the Accengage bridge in your application: ACCCustomTagProvider
  5. Add the acc_action key and fill the value with the Accengage SDK action you want to do. In that case, track_purchase.
  6. Then add the mandatory keys for a Purchase, acc_purchase_id,  acc_purchase_currency, and acc_purchase_total_price.
  7. Fill them with the appropriate values or variables.

Img

Update Device Information

There are two ways to use GTM to send an Accengage Update Device Information. Both of them have their own constraints and specificities. And both of them can be complementary.

Use Firebase Log Event

Like the other tracking methods, you can create a Tag to fire the Accengage updateDeviceInformation() method on a Firebase Log Event. That requires you to call a Firebase Log Event, instead of Firebase setUserProperty() method in your code to send an Update Device Information to Accengage immediately.

For that, you'll have to :

  1. Create a new Tag.
  2. Add a previously created trigger: AccengageUDITrigger for example.
  3. Set the tag type with Function Call.
  4. Indicate the classpath of the Accengage bridge in your application: ACCCustomTagProvider.
  5. Add the acc_action key and fill the value with the Accengage SDK action you want to do. There are four possible actions for updating device information in Accengage :

    • set_udi
    • delete_udi
    • increment_udi
    • decrement_udi
  6. Then add the keys you want to update in Accengage with the associated value.

Img

Use Firebase User Property

As expected, you may want to update Accengage device information on Firebase setUserProperty() method. At the moment, GTM triggers only fire when a Firebase Event occurs and all of the trigger conditions are true. That means you can create another Trigger for your Update Device Information action and add a condition for the a User Property in it. That trigger won't be immediatly fired after the Firebase setUserProperty() method, but after the next Firebase Event. For that, you'll have to:

  1. Create a new Tag.
  2. Create a new Trigger: AccengageUDITrigger for example.
  3. You can use a user property already tagged in your application as trigger (or use a regex to match every value tagged in your application for a user property).
  4. Set the tag type with Function Call.
  5. Indicate the class path of the Accengage bridge in your application: AccCustomTagProvider.
  6. Add the acc_action key and fill the value with the Accengage SDK action you want to do. There are four possible action for updating device information in Accengage:

    • set_udi
    • delete_udi
    • increment_udi
    • decrement_udi
  7. Then add the keys you want to update in Accengage with the associated value.

When you add key or value, you may want to use the value passed as parameters in the Firebase event method. For that, you need to create a Variable in the GTM interface to retrieve your event parameters. Then you will have the possibility to use those variables in your Tags or others.

Want to know more about what is a variable? please follow this link.

Do not hesitate to have a look at the Google Tag Manager official documentation for iOS and Android to deeply understand the Accengage GTM bridge.