Skip to content

Commit f6e4353

Browse files
authored
Merge pull request #906 from MaximBelov/fix-integration-with-google-tag-manager
fix: Integration with GoogleTagManager
2 parents 2f9858f + 36d0bae commit f6e4353

4 files changed

Lines changed: 99 additions & 4 deletions

File tree

README.md

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,24 +1657,77 @@ See the [iOS](https://firebase.google.com/docs/in-app-messaging/get-started?plat
16571657

16581658
# Google Tag Manager
16591659

1660-
Download your container-config json file from Tag Manager and add a `<resource-file>` node in your `config.xml`.
1660+
https://developers.google.com/tag-platform/tag-manager/mobile
16611661

16621662
## Android
16631663

1664+
1. Create directory `resources/android/containers`
1665+
1666+
1. Download your container-config json file from Tag Manager and add a `<resource-file>` node in your `config.xml`.
1667+
16641668
```xml
16651669
<platform name="android">
1666-
<resource-file src="GTM-XXXXXXX.json" target="assets/containers/GTM-XXXXXXX.json" />
1670+
<resource-file src="resources/android/containers/GTM-XXXXXXX.json" target="app/src/main/assets/containers/GTM-XXXXXXX.json" />
1671+
...
1672+
```
1673+
1674+
### Preview mode (optional)
1675+
(More info)[https://developers.google.com/tag-platform/tag-manager/android/v5#preview_container]
1676+
1677+
```xml
1678+
<platform name="android">
1679+
<config-file parent="/manifest/application" target="AndroidManifest.xml">
1680+
<activity android:exported="true" android:name="com.google.android.gms.tagmanager.TagManagerPreviewActivity" android:noHistory="true" tools:replace="android:noHistory">
1681+
<intent-filter>
1682+
<data android:scheme="tagmanager.c.{{BUNDLE_ID}}" />
1683+
<action android:name="android.intent.action.VIEW" />
1684+
<category android:name="android.intent.category.DEFAULT" />
1685+
<category android:name="android.intent.category.BROWSABLE" />
1686+
</intent-filter>
1687+
</activity>
1688+
</config-file>
16671689
...
16681690
```
16691691

16701692
## iOS
16711693

1694+
The application name should not contain spaces
1695+
1696+
```xml
1697+
1698+
<name short="Cordova App">CordovaApp</name>
1699+
1700+
```
1701+
1702+
1. Create directory `resources/ios/container`
1703+
1704+
1. Download your container-config json file from Tag Manager and to directory.
1705+
1706+
### Preview mode (optional)
1707+
(More info)[https://developers.google.com/tag-platform/tag-manager/ios/v5#preview_container]
1708+
1709+
1. Add `xmlns:tools="http://schemas.android.com/tools"` to `<widget>` tag
1710+
1711+
1. Add to config.xml
1712+
16721713
```xml
16731714
<platform name="ios">
1674-
<resource-file src="GTM-YYYYYYY.json" />
1715+
<edit-config file="*-Info.plist" mode="merge" target="CFBundleURLTypes">
1716+
<array>
1717+
<dict>
1718+
<key>CFBundleURLName</key>
1719+
<string>{{BUNDLE_ID}}</string>
1720+
<key>CFBundleURLSchemes</key>
1721+
<array>
1722+
<string>tagmanager.c.{{BUNDLE_ID}}</string>
1723+
</array>
1724+
</dict>
1725+
</array>
1726+
</edit-config>
16751727
...
1676-
```
1728+
</platform>
16771729

1730+
```
16781731
# Performance Monitoring
16791732

16801733
The [Firebase Performance Monitoring SDK](https://firebase.google.com/docs/perf-mon) enables you to measure, monitor and analyze the performance of your app in the Firebase console.

scripts/ios/after_plugin_install.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ module.exports = function(context) {
77
var xcodeProjectPath = helper.getXcodeProjectPath();
88
helper.removeShellScriptBuildPhase(context, xcodeProjectPath);
99
helper.addShellScriptBuildPhase(context, xcodeProjectPath);
10+
helper.addGoogleTagManagerContainer(context, xcodeProjectPath);
1011
};

scripts/ios/before_plugin_uninstall.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ module.exports = function(context) {
55
// Remove the build script that was added when the plugin was installed.
66
var xcodeProjectPath = helper.getXcodeProjectPath();
77
helper.removeShellScriptBuildPhase(context, xcodeProjectPath);
8+
helper.removeGoogleTagManagerContainer(context, xcodeProjectPath);
89
};

scripts/ios/helper.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,46 @@ module.exports = {
192192
fs.writeFileSync(path.resolve(xcodeProjectPath), xcodeProject.writeSync());
193193
},
194194

195+
addGoogleTagManagerContainer: function (context, xcodeProjectPath) {
196+
const appName = utilities.getAppName();
197+
const containerDirectorySource = `${context.opts.projectRoot}/resources/ios/container`;
198+
const containerDirectoryTarget = `platforms/ios/${appName}/container`;
199+
const xcodeProject = xcode.project(xcodeProjectPath);
200+
xcodeProject.parseSync();
201+
202+
if (utilities.directoryExists(containerDirectorySource)) {
203+
utilities.log(`Preparing GoogleTagManager on iOS`);
204+
try {
205+
fs.cpSync(containerDirectorySource, containerDirectoryTarget, {recursive: true});
206+
const appPBXGroup = xcodeProject.findPBXGroupKey({name: appName})
207+
xcodeProject.addResourceFile('container', {
208+
lastKnownFileType: 'folder',
209+
fileEncoding: 9
210+
}, appPBXGroup);
211+
fs.writeFileSync(path.resolve(xcodeProjectPath), xcodeProject.writeSync());
212+
} catch (error) {
213+
utilities.error(error);
214+
}
215+
}
216+
},
217+
218+
removeGoogleTagManagerContainer: function (context, xcodeProjectPath) {
219+
const appName = utilities.getAppName();
220+
const appContainerDirectory = `platforms/ios/${appName}/container`;
221+
const xcodeProject = xcode.project(xcodeProjectPath);
222+
xcodeProject.parseSync();
223+
if(utilities.directoryExists(appContainerDirectory)){
224+
utilities.log(`Remove GoogleTagManager container`);
225+
const appPBXGroup = xcodeProject.findPBXGroupKey({name: appName})
226+
xcodeProject.removeResourceFile('container', {
227+
lastKnownFileType: 'folder',
228+
fileEncoding: 9
229+
}, appPBXGroup);
230+
fs.writeFileSync(path.resolve(xcodeProjectPath), xcodeProject.writeSync());
231+
fs.rmSync(appContainerDirectory, {recursive: true});
232+
}
233+
},
234+
195235
ensureRunpathSearchPath: function(context, xcodeProjectPath){
196236

197237
function addRunpathSearchBuildProperty(proj, build) {

0 commit comments

Comments
 (0)