Utilizing Google Tag Manager with Custom Code

If you’re already using Google Tag Manager (GTM) on your website, you can leverage it to store UTM parameters in a browser cookie. This stored data can then be extracted and populated into hidden form fields, which are sent to Salesforce upon form submission. Attribution with Google Tag Manager and Custom Code. Here’s a step-by-step guide to the process:

  1. Install the “Persist Campaign Data” Tag Template:
    • Add the “Persist Campaign Data” tag template to your GTM account to capture UTM parameters from the URL.
  2. Set Up a Cookie Variable in GTM:
    • Configure a cookie variable in GTM to store the UTM parameter data.
  3. Integrate Custom Code:
    • Embed custom code on your website to extract the UTM data from the cookie and inject it into hidden form fields.

Attribution with Google Tag Manager and Custom Code


  • Cost-effective: GTM is free to use.


  • Technical Expertise Required: Setting up this process requires a solid understanding of GTM and the ability to modify code, making it best suited for those with technical resources.


  • Focus on UTM Parameters: This method captures UTM parameters from URLs, providing insights only into leads from paid campaigns, excluding organic channel attribution.

Implementing Attribution Snippets with GTM Across All Pages

To implement attribution snippets using GTM, follow these steps:

  1. Create a Custom HTML Tag:
    • In GTM, click “New” and select “Custom HTML Tag.”
    • Paste the code from your Attribution Settings into the HTML field.
    • Ensure the tag is triggered on all pages to install the attribution snippet uniformly.

Adding Attributes in Google Tag Manager:

  1. Access GTM Overview Page:
    • Click “Add a new tag.”
    • Select “Tag Configuration” and choose “Custom HTML.”
    • Embed the script that sends attributes to your designated tool in the HTML field.

Adding a Custom HTML Tag in GTM:

  1. Navigate to Tags:
    • Click “New.”
    • Select “Tag Configuration” and choose “Custom HTML.”
    • Insert the tag code from your vendor or your custom HTML/JavaScript into the HTML field.

Adding Code to GTM:

  1. Access the Workspace:
    • Locate your container ID (formatted as “GTM-XXXXXX”).
    • Click the container ID to open the “Install Tag Manager” box.
    • Follow the instructions to embed and activate the code snippets on your website.

Optimizing GTM Performance

  • Conduct Regular Audits: Remove unnecessary tags to improve load speeds.
  • Evaluate Tag Necessity: Prevent redundancy and streamline performance by assessing the need for each tag.

Differentiating GTM and Google Analytics

  • Google Analytics: Provides website and app analytics.
  • Google Tag Manager: Acts as a tag management system, enabling the addition and modification of tags for precise user event analysis.

Testing GTM Code

Employ a Tag Debugger:

  1. Open Developer Tools:
    • Navigate to the “ObservePoint” tab.
    • Refresh the page to observe captured network requests.
    • Filter the tags and inspect the variables to verify the presence and functionality of GTM container tags or other vendor tags.

Attribution with Google Tag Manager and Custom Code Changes

Is your business ready for the changes coming to Google’s data measurement infrastructure?

You probably rely on Google Analytics as a marvelous tool to understand your customers and better target their needs across both your web and mobile app platforms. But with changes on the way from Google, particularly with some legacy mobile app tracking and measurement platforms, the stability of your analytics might be at risk if you’re not prepared.

What’s changing?

The current version of Google Tag Manager (version 4, or “Legacy”) for mobile apps will no longer be supported by Google as of March 2020. But, limitations on the functionality of GTM version 4 have already begun. Due to these limitations and hard dates for deprecation, everyone will need to upgrade to Google Tag Manager version 5. This requires the implementation of new GTM and Firebase Software Development Kits and a switch from the current GTM in-app, data layer approach to the new Firebase, event-based, data collection process.

When will service be affected?

Here are the key dates and milestones shared by Google, subject to change (though unlikely):

  • As of June 30, 2019: You’re no longer able to create new containers of the Android (Legacy) or iOS (Legacy) types.
  • Jan. 31, 2020 (at the earliest; Google is still finalizing the official date): You’ll no longer be able to publish new changes to Legacy mobile app containers. The container versions that are currently live as of this date will continue working in your mobile apps, but will now be in read-only mode.
  • March 31, 2020: After this date, legacy mobile app containers will be removed from Google Tag Manager and will not longer be accessible. Your legacy mobile app containers will no longer gather or return any data. Requests will return a 204 (no content) response.

Will analytics measurement be affected?

Yes, for your mobile applications in particular. For your business to maintain uninterrupted Google Analytics tracking, you must make changes in the app source code. You’ll have to migrate the current data layer code in-app to Firebase-syntax data collection code, install a new Firebase SDK (if not already in place), create new GTM v5 containers, and test the new set-up for reliability to avoid any interruptions. InfoTrust can provide you with assistance to make this process as painless as possible. 

Please note, if you are already using Firebase Analytics and/or the newer version of Google Tag Manager for mobile apps, v5 (Firebase powered events and data collection), there is nothing to worry about and you are already in the safe zone. These dates are only meant to deprecate the measurement tracking for **Google Tag Manager v4 Legacy Containers** in mobile apps. This DOES NOT mean you have to move to Firebase Analytics and it DOES NOT mean GA for mobile apps is going away. Simply the means of collecting data in the app, if using GTM, is going through an upgraded version. You will need to update your source code to use the new GTM v5 SDK and Firebase event code, as described later but feel free to continue using GA as normal (if deployed in the new GTM v5 Firebase-powered containers).

Benefits of Switching

It’s not all bad news. Though the migration to GTM v5 will take some work, there are some major advantages. Most importantly, switching ensures uninterupted information flow to Google Analytics, so you never lose touch with your customers. Also, this isn’t just a cosmetic change; the switch to version 5 comes with more tags, new GTM capabilities, and new Firebase analytics UI capabilities.

Why InfoTrust?

If you’re still using version 4 of Google Tag Manager, this could be a complex project that requires input from many different parts of your business from IT to software development to analytics to marketing. Migrating platforms may be a little annoying, but it’s much less annoying than losing access to the key analytics tools or data you rely on to understand your customers and make strategic business decisions. Switching prevents headaches later and unlocks useful new features now. InfoTrust can help your organization come up with a solid migration plan, help work with your engineers to fully test and configure all the reporting + data measurement, and partner with your team to make the most out of the data collection and mobile application data you will continue to capture.

If you have any questions about any aspect of this process, don’t think twice about reaching out. We’d love to help. InfoTrust is here to make sure you’re data confident.

Related Posts
Salesforce Jigsaw
Salesforce Jigsaw

Salesforce.com, a prominent figure in cloud computing, has finalized a deal to acquire Jigsaw, a wiki-style business contact database, for Read more

Alphabet Soup of Cloud Terminology

As with any technology, the cloud brings its own alphabet soup of terms.  This insight will hopefully help you navigate Read more

We Are All Cloud Users
How Good is Our Data

My old company and several others are concerned about security, and feel more secure with being able to walk down Read more

Top Ten Reasons Why Tectonic Loves the Cloud
Cloud Managed Services

The Cloud is Good for Everyone - Why Tectonic loves the cloud  You don’t need to worry about tracking licenses. Read more