All Collections
Integrations
Other Integrations
Installation Guide: Google Tag Manager
Installation Guide: Google Tag Manager
Updated today

This guide will help you quickly set up Google Tag Manager and implement Retention’s Grow, Reclaim, and Revenue Tracking scripts.

The following topics will be covered:

  • Setting up a Google Tag Manager account

  • Finding your Retention scripts

  • Adding scripts to Google Tag Manager

    • Grow (Collection)

    • Reclaim (Viewed Product & Add To Cart)

    • Revenue Tracking

  • Suppression

  • Other Tags/Triggers


In the video below, we’ll show you how to set up a Google Tag Manager account, where to find your Retention.com snippet script code, how to add it to your Google Tag Manager, and how to set up different types of triggering events in Google Tag Manager.


How to set up Google Tag Manager account

To set up Google Tag Manager, you’ll first need to create a free account and connect it to an existing Google account.

1. Go to the Google Tag Manager site, and click Create Account.

2. Fill out the Account Setup information with your Account Name, Country, Container name — which is your website address — and your Target platform. Then, click Create.

3. After you’ve read the service agreement, click Yes.

4. Implement the Google tag manager code onto every page of your website. Paste the <head> code to the top of your pages and the <body> code after the body tag. If you have questions about adding the code to your page, click Quick Start Guide.


Where to find your Retention.com script

From your Retention.com Dashboard, click Code Script. Then, click View Your Script.

2. Check the box next to Collection, and then click Copy Code </>. You’ll see a green box in the top right-hand corner telling you the code was copied to your clipboard.

Copy Collection

Remember: You can’t check multiple boxes for scripts or you will get an error message. You can only copy one at a time.


How to add Retention script in Google Tag Manager

The following steps guide you through the process of integrating our Grow (Collection) script.

Subsequent to this section, you will find detailed instructions on how to implement our Reclaim scripts, specifically for Viewed Product and Add to Cart functionalities.

Please ensure you set up a tag for the base script before implementing the Reclaim scripts. Instructions can be found here.


1. Log in to Google Tag Manager. Click New Tag.

2. You can give the tag a title at the top. Click the pencil image in the Tag Configuration section.

3. Click Custom HTML under Custom.

4. Paste your Retention script into the HTML box.

5. You will need to choose a trigger at the bottom to make the tag fire. Click the pencil icon in the Triggering section.

6. Choose a trigger, such as page views on all pages.

Note for SPA/React sites: You should set your Triggers for All Pages as seen above, as well as All History Events:

7. Once you have chosen a trigger, click Save in the top right.


How to test your script to confirm it's working


How to add Reclaim scripts to Google Tag Manager

The Reclaim scripts will require you to use variables accessible within GTM. If you are having trouble determining what variables to use or how to find them, please use the Google Tag Manager "preview" or "debug" mode. For more information please click here.

Click here to implement the "Viewed Product" script

1. Log in to Google Tag Manager. Click New Tag.

2. Give the tag a relevant title at the top (Recommended practice is to include Retention and the name of the script). Click the pencil image in the Tag Configuration section.

3. Click Custom HTML under Custom.

4. Copy and paste the script below into the HTML box.

Note - You will be required to update the "vpitem" variable in the code below with all the appropriate product information.

The following fields are recommended*:

  • Name of Product

  • Price

  • ProductID

  • Categories (if applicable)

  • ImageURL

  • Brand (if applicable)

*Please add/remove as required.

The Google Tag Manager preview tool might be beneficial in retrieving dynamic product information from your product pages.

<script type="text/javascript">
var vpitem = {
productID: {{update_with_value}},
productName: {{update_with_value}},
imageURL: {{update_with_value}},
price: {{update_with_value}},
url: window.location.href,
brand: {{update_with_value}},
hostname: {{Page Hostname}},
};

if (window.location.href.includes('vge=true')) {
console.log('Viewed Product Reclaim', vpitem);
}

if (typeof geq !== 'undefined' && typeof geq.event === 'function') {
geq.event('Viewed Product Reclaim', vpitem);
}

</script>

5. Under "Advanced Settings", locate "Tag Sequencing". Select the checkbox for "Fire a tag before __ fires" and then proceed to select the Retention Base Script tag.

For instructions on how to set up the Retention Base Script tag, please click here.


6. You will need to choose a trigger at the bottom to make the tag fire. Click the pencil icon in the Triggering section.

7. Click on the "+" on the right of the page to create a new trigger

8. Give the trigger a relevant title at the top, then click the pencil image in the Tag Configuration section.

9. Select "Window Loaded" from the Page View list of triggers

10. Choose the "Some Window Loaded Events" option and set up specific triggers that activate when a user visits your product page. Typically, product pages are identifiable by specific terms like "product" in their URL or Page Path, setting them apart from other pages on your website. Your aim is to pinpoint and utilize these unique identifiers to accurately target your product pages.

In the screenshot below, two different triggers, Page Path and Page Hostname, are used to validate if a user has landed on a product page.

11. Save your trigger and your tag. The script has now been added and will be triggered whenever a user lands on a product page. You can verify if the script is functioning correctly via the Retention Debugger or the Google Tag Manager Preview Tool.

Click here to implement the "Add To Cart" script

1. Log in to Google Tag Manager. Click New Tag.

2. Give the tag a relevant title at the top (Recommended practice is to include Retention and the name of the script). Click the pencil image in the Tag Configuration section.

3. Click Custom HTML under Custom.

4. Copy and paste the script below into the HTML box.

Note - You will be required to update the "atcitem" variable in the code below with all the appropriate product information.

The following fields are recommended*:

  • Name of Product

  • Price

  • ProductID

  • Categories (if applicable)

  • ImageURL

  • Brand (if applicable)

*Please add/remove as required.

The Google Tag Manager preview tool might be beneficial in retrieving dynamic product information from your product pages.

<script type="text/javascript">
var atcitem = {
productID: {{update_with_value}},
productName: {{update_with_value}},
imageURL: {{update_with_value}},
price: {{update_with_value}},
url: window.location.href,
brand: {{update_with_value}},
hostname: {{Page Hostname}},
};

if (window.location.href.includes('vge=true')) {
console.log('Add to Cart Item:', atcitem);
}

if (typeof geq !== 'undefined' && typeof geq.addToCart === 'function') {
geq.addToCart(atcitem);
}

</script>


5. Click on the "Advanced Settings" dropdown at the bottom of the tag configuration window.


6. Under "Tag Sequencing", select the checkbox for "Fire a tag before __ fires" and then proceed to select the Retention Base Script tag.

For instructions on how to set up the Retention Base Script tag, please click here.

7. You will then need to choose a trigger at the bottom to make the tag fire. Click the pencil icon in the Triggering section.

8. Click on the "+" on the right of the page to create a new trigger

9. Give the trigger a relevant title at the top, then click the pencil image in the Tag Configuration section.

10. Select "Custom Event" from the "Other" list of triggers.

11. Fill in the Event Name field with the event thats linked to clicking on the "add to cart" button on your product pages. You can additional trigger features to ensure this code fires on product pages only.

If you are having trouble determining what event to use or how to find an event name, please use the Google Tag Manager "preview" or "debug" mode. For more information please click here.

12. Save your trigger and your tag. The script has now been added and will be triggered whenever a user adds an item to their cart from a product page. You can verify if this script is functioning correctly via the Retention Debugger or the Google Tag Manager Preview Tool.


How to add Revenue Tracking script

1. Log in to Google Tag Manager. Click New Tag.

2. Give the tag a relevant title at the top (Recommended practice is to include Retention and the name of the script). Click the pencil image in the Tag Configuration section.

3. Click Custom HTML under Custom.

4. Copy and paste the script below into the HTML box.

Note - You will be required to update the parameters in the code below with the appropriate values.

The following fields are required*:

  • order_number

  • order_amount

  • order_email

<script>
window.geq.trackOrder({
order_number: {{data_layer___eventModel.transaction_id}},
order_amount: {{data_layer___eventModel.value}},
order_email: {{custom_js___email}}
});
</script>


5. Click on "Advanced Settings" and locate "Tag Sequencing". Select the checkbox for "Fire a tag before __ fires" and then proceed to select the Retention Base Script tag.

For instructions on how to set up the Retention Base Script tag, please click here.

6. You will need to choose a trigger at the bottom to make the tag fire. Click the pencil icon in the Triggering section.

7. Click on the "+" on the right of the page to create a new trigger

8. Give the trigger a relevant title at the top, then click the pencil image in the Tag Configuration section.

9. Select "Custom Event" from the Other triggers list.

10. Fill in the Event Name field with the event thats linked to a customer successfully purchasing from your site.

If you are having trouble determining what event to use or how to find an event name, please use the Google Tag Manager "preview" or "debug" mode. For more information please click here.

11. Save your trigger and your tag. The script has now been added and will be triggered whenever a user purchases something. You can verify if this script is functioning correctly via the Retention Debugger or the Google Tag Manager Preview Tool.


How to suppress form submissions

You can set a Trigger in Google Tag Manager to suppress visitors who submit their email address via a form or pop-up on your site.

1. From your Google Tag Manager Workspace, click Triggers > New.

2. Click in the box to choose a trigger type, and select Form Submission.

3. Give the trigger a name at the top.

Enable Check Validation.

To enable the trigger on all pages (recommended), use this logic:

Page Path > contains > /

4. You will also need to know what other forms are coming to your site so you can exclude them. That keeps the suppression script from firing when those forms/pixels come to your site (instead of only on the form submission).

Choose Form URL > does not contain > (the form URL source).

If you aren't sure what forms you have on your site, you can use this logic to prevent it from firing:

The trigger fires on Some Forms

Fire this trigger when an Event occurs and all of these conditions are true:

Form URL > does not contain > facebook
Form URL > does not contain > search
Form URL > does not contain > find
Form URL > does not contain > get

Note: You can adjust what the form URL does not contain to match your site's search functions. The solution above takes into consideration if Facebook is enabled and also applies to your search forms.

5. You will then need to create a Tag for this trigger. From your Workspace, click Tag > New.

6. Click inside the Tag Configuration box and choose Custom HTML as the tag type.

7. Give the Tag a name at the top and then paste your suppression script from Retention.com in the box. (Find your suppression script by going to Code Script > View Your Script > Suppression > Copy Code in Retention.com.)

8. Click the Triggering box at the bottom and choose the form submission trigger you created in the previous steps.

9. Click Save.

10. Make sure this container version is published and set as live.


How to fire base script only

Click here to expand

If you set a trigger to only fire your collection script based on a time delay, page views, or other factor that keeps it from firing immediately—but also have other scripts on your site that need to fire immediately such as the Add to Cart or Product View scripts—you will need to create a Tag for our base script. The base script must be present/fire before any other script will be able to fire, and it does not collect contacts.

1. Follow the steps above for "How to add snippet script." When you paste the collection script in the HTML box (Step 4), delete '<script>geq.page()</script>' from the bottom line:

That will leave you with only the base script:

Remember: You will need to use the script from your account, as the example above does not have your account's key.

2. Add a Trigger to fire this Tag on All Page Views. This script will not collect contacts and only needs to be added if you don't have the collection script firing immediately on pages where you want to use the Add to Cart or Product View scripts.


How to exclude traffic by referral source

Click here to expand

1. To exclude traffic by referral source, start by creating a new trigger. Click the plus sign in Triggering.

2. Click the plus sign.

3. Name it “Exclude” and then the source name (ex. Exclude Taboola). Click in the Trigger Configuration box. Choose Custom Event as the trigger type.

4. Give the event a name (Taboola). Change it to Some Custom Events and then choose Referrer, does not contain and then the name of the source, which would be Taboola in this example. Then, click Save at the top.

5. Once the trigger is saved, click New Tag.

6. Name the tag “Exclude Taboola,” or whatever the source name is. Click in the Tag Configuration box, and choose Custom HTML.

7. Paste your Retention.com script in the HTML box. Click in the Triggering box.

8. Choose the Exclude Taboola trigger you created, and click Save.


How to set the script to fire after a specific number of page views

Click here to expand


To fire a trigger after a certain number of page views, you’ll need to first create a new variable.

1. Click Variables and then New.

2. Click in the Variable Configuration box, and choose 1st Party Cookie.

3. Name the variable Cookie - Page Count at the top and the Cookie Name Page Count. Then, under Format Value, put Convert null to as zero and Convert undefined to as zero, and click Save.

4. You’ll then need to create a Custom HTML Tag to read the value in the variable. To do that, go through the Tag steps again: New Tag > Tag Configuration > Custom HTML. Paste the HTML code you create that includes the variable and number of page views you set in the box.

5. You’ll need to add a trigger for the Tag to fire, so click the Triggering box > plus sign > Trigger Configuration > Page View.

6. Name the trigger (ex. Page View Trigger). Select Some Page Views. Then, set these conditions:

Page Count > greater than > 1 (adjust the variable to whatever you used and the number to how many pages you want them to view before it fires).

Remember: The number used here needs to match the one in the custom HTML code you used.

7. Click Save.

Did this answer your question?