With iOS and Android containers available for Google Tag Manager, it's tempting to add GTM as an integration into an existing Firebase setup for your apps. It's also a fine way to get acquainted with Firebase in the first place, as it has a plethora of features to make application development easier.

Furthermore, with the advent of App + Web, there's even more incentive to integrate your app with Firebase.

Adding Google Tag Manager is basically one extra dependency, and even if the feature set at the moment isn't too spectacular, I'd be surprised if things like custom templates wouldn't make their way to mobile at some point.

In this article, I'll show a simple trick to keep your Google Tag Manager containers for iOS and Android in sync. They share the same core functionality, so exporting and importing containers across the two platforms is quite frictionless. However, there are some compatibility issues you need to tackle before transferring the data across the platform boundary.

Tip 110: Keep iOS and Android GTM containers in sync

First of all, this will not work with legacy GTM containers. The containers must be Firebase (i.e. the latest version of Google Tag Manager for apps).

To sync the containers, you need to export the workspace JSON from the source, and import it into the target. You can read this instruction to learn about importing and exporting in general.

Modify the usageContext key

If you want the import/export to work across platforms (Android to iOS, or vice versa), there's one parameter value that you need to change in the JSON. There's a key named containerVersion.container.usageContext that you need to edit. Here's what it looks like on Android:

{
    "exportFormatVersion": 2,
    "exportTime": "2020-03-13 07:15:59",
    "containerVersion": {
        ...
        "container": {
            ...
            "usageContext": [
                "ANDROID_SDK_5"
            ],
            ...
        },
    ...
    }
}

With iOS it's almost the same, except the value is ["IOS_SDK_5"].

So, if you want your Android container to work in iOS, you need to change the value from ["ANDROID_SDK_5"] to ["IOS_SDK_5"].

If you want your iOS container to work in Android, you need to change the value from ["IOS_SDK_5"] to ["ANDROID_SDK_5"].

Once you've made those changes, the container should be importable between the two platforms.

However, there are certain triggers and variables that only work in one platform but not the other. You need to delete these from the container JSON if you want the import/export to work.

Incompatibilities

Once you've made the change in the previous chapter, you might see the following error when trying to import the container:

This is because there are incompatibilities between some triggers and variables between the two platforms. I've listed them in this table:

Type Name Compatibility
Trigger App Exception Android only
Trigger App Update iOS only
Trigger First Open iOS only
Trigger In-App Purchase iOS only
Trigger Notification Dismiss Android only
Trigger Notification Receive Android only
Variable Device ID Android only
Built-in Variable App Version Name Android only
Built-in Variable In-app Purchase * iOS only
Built-in Variable Notification * iOS only

If the item is “X only”, it will only work in that type of container, and must be deleted from the export if you want to import the JSON into the other type of container.

To delete an item, you need to delete the entire object block containing the parameters. The block starts with { and ends with }. For example, if you wanted to delete the item from the screenshot above, you'd find the following block and delete it.

{
    "accountId": "23019854",
    "containerId": "2750082",
    "triggerId": "42",
    "name": "First Open",
    "type": "FIREBASE_FIRST_OPEN",
    "fingerprint": "1584083607944"
}

Built-in Variables are an exception - they won't break the import/export, but they simply won't appear in the target container in the list of Built-in Variables. Any tags, triggers, or variables that reference the missing Built-in Variables will retain those references, meaning the container will not validate if you try to create a version or publish it. You need to manually edit each of these missing variable links to make the container work.

Note that all the In-App Purchase and all the Notification Built-in Variables are iOS only.

Once you've handled all the incompatibilities, the import/export should work without a hitch.

Summary

Hopefully iOS and Android containers will converge even more in the future, so that you don't have to manually make any edits to get the sync to work in Google Tag Manager.

Or, even better, hopefully GTM will handle the cross-platform import/export gracefully, automatically changing what can be changed, and flagging differences that require manual input clearly in the interface.

Having said that, it's still so much easier to import/export across platforms with Firebase containers compared to what we had with the legacy Google Tag Manager containers.

The edits you have to make to get the conversion to work are fairly minor. The bigger headache is trying to figure out how to replace the functionality of items that are not supported. For example, if you have a trigger for In-App Purchase running in iOS, there just isn't a similar built-in trigger in Android. You'd need to implement a custom solution to handle this tracking.

Keeping the containers in sync is more than just editing the JSON. But knowing what changes need to be made is a good first step in improving the workflow - that's why I considered this article to be useful in the first place.

Let me know in the comments if you have trouble getting the containers to sync across platforms!