简体   繁体   English

如何将 Google 标签管理器与 React Native 应用程序集成?

[英]How to integrate Google Tag Manager with React Native app?

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.最近市场部让我在现在的公司项目中加入Google Tag Manager,这个项目是基于React Native写的,我找了很多。 but no success to found good updated documentation.但没有成功找到好的更新文档。

I found a react-native-gtm but it is for 4 years ago.我找到了一个react-native-gtm ,但它是 4 年前的。 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.此外,我找到了一些像这样的 Native 方面的描述,但它完全适用于 Native iOS 而不是 React Native 项目。

Also, I found an article with the React Native: Firebase GTM Integration Installation title.另外,我找到了一篇标题为React Native: Firebase GTM Integration Installation的文章。 but what is it?但它是什么? What is the meaning of Firebase GTM ? Firebase GTM是什么意思? what does it mean?这是什么意思?

Because as I remember these are separated tools for marketing.因为我记得这些是用于营销的独立工具。 Firebase is different from GTM. Firebase 与 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.它不是 React Native 解决方案。

So: How to integrate Google Tag Manager with React Native app?那么:如何将 Google Tag Manager 与 React Native 应用程序集成?

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/所以我假设您已经设置了 firebase,如果没有按照此处的指南进行操作: https://rnfirebase.io/

FOR iOS:对于 iOS:

  1. enter the line below into your podfile pod 'GoogleTagManager'在您的 podfile pod 'GoogleTagManager'中输入以下行

  2. then run: pod install然后运行: pod install

  3. 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在项目根目录中,创建一个 GTM 容器文件夹并将来自 GTM 仪表板的容器 json 文件存储在其中<project-ios-root>/container/GTM-XXXXXX.json

FOR ANDROID:对于 ANDROID:

  1. in your app level build.gradle file, add the following to the dependencies block:在您的应用程序级别build.gradle文件中,将以下内容添加到依赖项块:

dependencies {依赖关系{
//... //...
implementation 'com.google.android.gms:play-services-tagmanager:17.0.0'实施 '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 2. 在以下路径中创建 GTM Containers 文件夹<project-android-root>/app/main/assets/containers并在其中存储 JSON 文件, <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") .请注意,如果您的 gradle 构建工具低于版本 4,您将收到构建错误。在这种情况下,在您的项目级别build.gradle文件中,使用以下命令更新依赖项块中的 gradle 构建工具: 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.另外,是 android 的“容器”和 iOS 的“容器”用于 GTM 容器文件夹存储 JSON 文件。

I found this article very helpful in explaining the differences between Firebase Analytics and Google Analytics.我发现这篇文章非常有助于解释 Firebase Analytics 和 Google Analytics 之间的区别。 In short, you need to use Firebase Analytics in the app, with a package like react-native-firebase .简而言之,您需要在应用程序中使用 Firebase Analytics,并使用 package 之类react-native-firebase firebase 。 You can integrate tag manager from the console.您可以从控制台集成标签管理器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM