iOS | How to setup Google Tag Manager for multiple environments The integration requires that we have a folder (not group!) with the name “container” inside app workspace. Within this folder the container file should be located. This raises my issue: We have two different GTM Containers, one for the testing/development app and one for production.
- By using a folder it is not possible for me to add a different container file and set target references.
- I can not create an additional folder since google tag manager environments requires the folder on root level and with the exact name “container”.
We should be able to configure an XCode “run script” build step that clears the container directory and copies the correct container into place. Go through following steps to resolve this issue –
-
- For multiple GTM container JSON file (say Prod and QA), c Copy the downloaded json file into a folder called ‘container’ in your XCode project root directory
- Click on ‘Build Phase’, add a new Run Script, and paste the code in the screenshot below or paste the following into your new script area;
rm -vf ${SRCROOT}/container/* if [ “${CONFIGURATION}” = “Release” ]; then #echo Do something really release-like cp “${SRCROOT}/GTMFile/GTM-your file name.json” “${SRCROOT}/container/” else cp “${SRCROOT}/GTMFile/GTM-your file name.json” “${SRCROOT}/container/” fi
And it’s done. Build and run, you will have single json for the respective configuration..