Tracking Template Checker Script

In Google Ads Troubleshooting · Updated (1 months ago)

Find Hidden Tracking Templates Instantly As mentioned in our troubleshooting guide, tracking templates set at the Ad or Keyword level will override your Account-level setup, preventing ClickPatrol from working. Finding these manually in a large account is nearly impossible.

This Google Ads script scans your entire account (Campaigns, Ad Groups, Ads, Keywords, and Video Ads) and generates a simple log of every tracking template currently in use.

The Script#

/**
 * Google Ads Script: Enhanced <a href="https://clickpatrol.com/knowledge-base/i-have-issues-with-tracking-templates/">Tracking Template</a> Checker
 
Description:
This script is designed for Google Ads accounts to review tracking templates across various entity types such as campaigns, keywords, video ads, etc. Upon execution, it provides an overview of the tracking templates utilized by these entities.

Installation:
1. Log into your Google Ads account.
2. Navigate to 'Tools & Settings' (typically represented by a wrench icon) on the top menu bar.
3. Under 'Bulk Actions', find 'Scripts' and click on it.
4. Click on the blue '+' button to create a new script.
5. In the script editor, clear any default code (if present) and paste this script.
6. Click 'Save' to store the script.

Usage:
After <a href="https://clickpatrol.com/knowledge-base/what-are-budget-reallocations-on-clickpatrol/">saving</a> the script:
1. Click the 'Preview' button (usually an eye icon) in the script editor to run it in preview mode. This will execute the script without making changes, allowing you to detect any issues.
2. Once previewed and satisfied, click the 'Run' button to execute the script.
3. After the script executes, navigate to the 'Log' (usually represented by a notepad icon) to view the results. Here, you'll see the tracking templates used by various entities in your Google Ads account.

 * Author: Bernt Muurling
 * Updated by: Taskforce <a href="https://clickpatrol.com/agency/">Agency</a> & ClickPatrol
 * Version: 1.1
 */

// Entry point function
function main() {
  try {
    checkTrackingTemplates();
  } catch (e) {
    Logger.log("An error occurred: " + e.message);
  }
}

// Function to check tracking templates for various entity types
function checkTrackingTemplates() {
  var entityTypes = [
    { level: 'Campaign', selector: AdsApp.campaigns().withCondition('Status = ENABLED'), getUrlsMethod: entity => entity.urls() },
    { level: 'Keyword', selector: AdsApp.keywords().withCondition('Status = ENABLED'), getUrlsMethod: entity => entity.urls() },
    { level: 'VideoAd', selector: AdsApp.videoAds().withCondition('Status = ENABLED'), getUrlsMethod: entity => entity.urls() },
    { level: 'Ad', selector: AdsApp.ads().withCondition('Status = ENABLED'), getUrlsMethod: entity => entity.urls() },
    { level: 'AdGroup', selector: AdsApp.adGroups().withCondition('Status = ENABLED'), getUrlsMethod: entity => entity.urls() }
  ];

  entityTypes.forEach(entityType => {
    processEntities(entityType);
  });
}

// Process each entity type and log tracking templates
function processEntities(entityType) {
  var iterator = entityType.selector.get();
  while (iterator.hasNext()) {
    var entity = iterator.next();
    var urlsMethodInstance = entityType.getUrlsMethod(entity);
    var <a href="https://clickpatrol.com/knowledge-base/how-to-troubleshoot-your-clickpatrol-dashboard-not-showing-any-traffic/">trackingTemplate</a> = urlsMethodInstance.getTrackingTemplate();

    if (<a href="https://clickpatrol.com/knowledge-base/how-to-troubleshoot-your-clickpatrol-dashboard-not-showing-any-traffic/">trackingTemplate</a>) {
      var entityIdentifier = (typeof entity.getName === 'function') ? entity.getName() : entity.getId();
      Logger.log(entityType.level + ' "' + entityIdentifier + '" uses <a href="https://clickpatrol.com/knowledge-base/i-have-issues-with-tracking-templates/">tracking template</a>: ' + trackingTemplate);
    }
  }
}

Copy the code below to use in the installation steps:

1. Installation Steps#

  1. Log in to your Google Ads account.
  2. Navigate to Tools & Settings (wrench icon in the top menu).
  3. Under Bulk Actions, select Scripts.
  4. Click the blue Plus (+) button to create a new script.
  5. Delete any default code in the editor and paste the script provided above.
  6. Click Save.

2. Authorization & Execution#

Before the script can read your data, you must authorize it.

  1. Click the Preview button (eye icon) inside the script editor.
  2. A pop-up will appear asking for permission. Click Authorize and follow the prompts.
  3. Once authorized, click Preview again to run the script in test mode, or click Run to execute it immediately.

3. Viewing the Results#

Once the script has finished running:

  1. Click on the Logs tab (usually found at the bottom or next to the 'Editor' tab).
  2. Review the list. The script will print out every entity that has a tracking template.
  3. What to look for: Look for any template that does not contain clckptrl.com. These are the specific ads or keywords blocking ClickPatrol. You must remove or merge these templates.

Was this article helpful?

Let us know so we can improve our documentation

Thanks for your feedback!

Need Help?

If something isn't working or you have questions, our support team is here to help you.

Contact Support