An Expo config plugin that sets up Google Tag Manager for Firebase (GTM SDK v5) on iOS and Android during expo prebuild.
It does three things:
- adds the GTM native SDK (
GoogleTagManagerpod,com.google.android.gms:play-services-tagmanager) through Expo autolinking - copies your exported container JSON files into the right native folders
- iOS:
ios/<App>/container/GTM-XXXX.json, added to Xcode as a folder reference (blue folder) in the app target's Copy Bundle Resources phase - Android:
android/app/src/main/assets/containers/GTM-XXXX.json
- iOS:
- optionally registers the GTM preview URL scheme (iOS) and
TagManagerPreviewActivity(Android)
It does not add a JavaScript API. See Why no JS API.
-
An Expo project that uses Continuous Native Generation (
expo prebuild) or a development build. Expo Go is not supported. -
@react-native-firebase/appand@react-native-firebase/analytics, installed and configured with yourGoogleService-Info.plistandgoogle-services.json. GTM listens to Firebase Analytics events, so Firebase must be set up first. -
iOS static frameworks, which React Native Firebase already requires:
["expo-build-properties", { "ios": { "useFrameworks": "static" } }]
-
One container per platform, exported from the GTM web UI. GTM uses separate containers for iOS and Android.
yarn expo install expo-google-tag-managerAdd the plugin to app.json (or app.config.js):
{
"expo": {
"ios": { "bundleIdentifier": "com.example.app" },
"android": { "package": "com.example.app" },
"plugins": [
"@react-native-firebase/app",
["expo-build-properties", { "ios": { "useFrameworks": "static" } }],
[
"expo-google-tag-manager",
{
"ios": { "container": "./gtm/GTM-IOS1234.json" },
"android": { "container": "./gtm/GTM-AND5678.json" },
"enablePreview": true
}
]
]
}
}Then regenerate the native projects:
yarn expo prebuild --clean| Option | Type | Default | Description |
|---|---|---|---|
ios.container |
string |
— | Path to the iOS container JSON, relative to the project root. |
android.container |
string |
— | Path to the Android container JSON, relative to the project root. |
enablePreview |
boolean |
false |
Registers the GTM preview URL scheme on iOS and the preview activity on Android. |
Rules:
- Set at least one of
iosorandroid. - Name each container file after its GTM id, like
GTM-XXXX.json. The file must exist and contain valid JSON. GTM downloads already use this name. enablePreviewneedsios.bundleIdentifierandandroid.packagein your app config.- The plugin checks the container files during
expo prebuild, not when Expo reads the config.expo startandeas updatework even where thegtm/folder is missing. - The plugin owns the native
containerandcontainersfolders. Each prebuild replaces their contents, so a renamed or removed container does not stay behind. Turning offenablePreviewor removing a platform also removes what the plugin added before.
- Open tagmanager.google.com and select the iOS or Android container.
- Click Versions, open the version you want, then Actions → Download.
- Save the file in your project (for example
gtm/GTM-XXXX.json) and commit it. - Repeat for the other platform's container.
Run yarn expo prebuild again after you replace a container file.
With enablePreview: true:
- iOS:
Info.plistgets the URL schemetagmanager.c.<bundleIdentifier>. - Android:
AndroidManifest.xmlgetscom.google.android.gms.tagmanager.TagManagerPreviewActivitywith an intent filter for the schemetagmanager.c.<package>.
To preview a container version:
- In GTM, click Preview on the container. GTM shows a preview link and a QR code.
- Close the app on the device or simulator.
- Open the preview link on the device (scan the QR code, or run
xcrun simctl openurl booted "<link>"/adb shell am start -a android.intent.action.VIEW -d "<link>"). - The app opens with the preview container. Fire your Firebase Analytics events and check that the tags run.
On Android, adb shell setprop log.tag.GoogleTagManager VERBOSE shows GTM logs in Logcat.
GTM for Firebase has no runtime API worth wrapping. Your app logs events to Firebase Analytics, and GTM reacts to those events on the device. Use React Native Firebase directly:
import { getAnalytics, logEvent } from '@react-native-firebase/analytics';
await logEvent(getAnalytics(), 'purchase', { value: 9.99, currency: 'USD' });There is no push() or data layer, and no support for custom JavaScript tags or variables. The legacy GTM SDKs (v3/v4) are not supported.
MIT