Recently, the marketing team asked me to add Google Tag Manager in the current company project, this project is written based on React Native
and I searched a lot for this. but no success to found good updated documentation.
I found a react-native-gtm
but it is for 4 years ago. also, I find some descriptions for the Native side like this, but it’s exactly for the Native iOS not for a React Native project.
Also, I found an article with the React Native: Firebase GTM Integration Installation
title. but what is it? What is the meaning of Firebase GTM? what does it mean?
Because as I remember these are separated tools for marketing. Firebase is different from GTM. By the way, this current article is not useful for us because it describes installing on the Native sides. it is not a React Native solution.
So: How to integrate Google Tag Manager with React Native app?
Advertisement
Answer
The way I went about this was to handle the integration for both platforms natively. So I assume you already have firebase set up, if not follow guide here: https://rnfirebase.io/
FOR iOS:
enter the line below into your podfile
pod 'GoogleTagManager'
then run:
pod install
in the project root, create a GTM container folder and store the container json file from GTM dashboard in it
<project-ios-root>/container/GTM-XXXXXX.json
FOR ANDROID:
- in your app level
build.gradle
file, add the following to the dependencies block:
dependencies {
// …
implementation ‘com.google.android.gms:play-services-tagmanager:17.0.0’
} 2. Create GTM Containers folder in the following path<project-android-root>/app/main/assets/containers
and store the JSON file in it as well,<project-android-root>/app/main/assets/containers/GTM-XXXXX.json
note you will get a build error if your gradle build tool is less than version 4. In that case in your project level build.gradle
file, update the gradle build tool in the dependencies block with this:
classpath("com.android.tools.build:gradle:4.0.1")
.
Also, yes “containers” for android and “container” for iOS for the GTM container folder to store the JSON files.