How to Set Up a Precautionary Ad Tracking Script
Adding a precautionary ad tracking script helps protect your attribution data if your standard tracking template does not apply correctly. This script acts as a fallback by automatically applying tracking parameters, ensuring your campaign data remains accurate and reliable.
TABLE OF CONTENTS
- What This Script Does
- Before You Start
- How to Set Up the Precautionary Tracking Script
- Why This Matters
- Frequently Asked Questions
- Need Help?
What This Script Does
A precautionary tracking script provides an additional layer of protection for your campaign tracking.
Instead of relying solely on your primary tracking setup, this script ensures that tracking parameters are still applied even if something fails. This helps:
Preserve attribution data
Maintain accurate reporting
Reduce gaps in campaign tracking
Improve overall data reliability
The script dynamically updates tracking templates using campaign, ad group, and ad-level data, ensuring consistency across your campaigns.
Before You Start
Before setting up the script, make sure you have the following:
Access to your ad platform account
Permission to create or edit scripts
The correct landing page or tracking URL
Awareness that scripts can affect existing tracking setups
It is also important to preview and authorize the script before enabling it.
How to Set Up the Precautionary Tracking Script
Open the Scripts Section
Log in to your ad platform account and navigate to the scripts area.
Open Tools and Settings
Go to Bulk Actions
Select Scripts
This is where you can create and manage tracking scripts.
Add the Tracking Script
Create a new script or edit an existing one.
Remove any placeholder code and paste the following script:
function main() { var TrackingTemplate = "{lpurl}?utm_source=adwords&utm_medium={AdName}&utm_campaign={CampaignName}&utm_content={AdGroupName}&utm_keyword={keyword}&utm_matchtype={matchtype}&campaign_id={campaignid}&ad_group_id={adgroupid}&ad_id={creative}"; var _CAMPAIGN_CONTAINS = ""; var _ADGROUP_CONTAINS = ""; var STATUS = "ENABLED"; if (TrackingTemplate.search(/{AdGroupName}|{CampaignName}|{AdName}/g) == -1) { Logger.log("Enter at least one required parameter"); return } var adgroupIterator = AdsApp.adGroups().withCondition("Status = " + STATUS).get(); while (adgroupIterator.hasNext()) { var adgroup = adgroupIterator.next(); var template = TrackingTemplate .replace(/{AdGroupName}/g, adgroup.getName().replace(/\s/g, '%20')) .replace(/{CampaignName}/g, adgroup.getCampaign().getName().replace(/\s/g, '%20')); adgroup.urls().setTrackingTemplate(template); } }
Make sure the landing page URL in the script matches your website.
Rename and Schedule the Script
After saving:
Give the script a clear name (e.g., Tracking Backup Script)
Set the frequency to Hourly
Running the script hourly ensures tracking remains updated and consistent.
Preview, Authorize, and Enable
Before enabling the script:
Run a Preview to verify it detects campaigns correctly
Review logs to ensure no errors appear
Complete the Authorization process
Enable the script
Previewing helps prevent issues before applying live changes.
Why This Matters
Without a fallback system, missing or broken tracking templates can lead to inaccurate data.
This script helps you:
Protect attribution accuracy
Ensure consistent campaign tracking
Improve reporting reliability
Reduce manual troubleshooting
Frequently Asked Questions
Q: Will this affect my existing scripts?
Yes, scripts can impact tracking settings. Always review your current setup before enabling.
Q: Why is authorization required?
Authorization is necessary because the script makes changes within your ad account.
Q: Should I preview the script first?
Yes. Previewing ensures everything works correctly before applying live changes.
Q: What should I update in the script?
Verify that the landing page URL and tracking parameters match your setup.
Q: Do I still need my original tracking template?
Yes. This script is a backup, not a replacement.
Need Help?
If you need help reviewing your tracking setup or validating your script configuration, open the Help Center or contact support for assistance.
Was this article helpful?
Related articles
- Create a new Google Search Ad CampaignAd Manager allows you to run the ad campaigns on Google. Your Google Ads campaign is entirely in your control: design your ad content, choose your daily budget and set a specific target audience with geography and languages. TABLE OF CONTENTS - Step 1 | Create Campaign - Step 2 | Ad Content- Add Ad Manager
- Guidelines for using custom questions in Google lead formsWhen creating a lead form using Ad Manager for Google Ads, you may want to ask custom questions to better qualify your leads. However, Google enforces strict guidelines for what kinds of questions are allowed. This article explains what types of custom questions are approved, and how to avoid issuesAd Manager
- How to connect Instagram account with Facebook page?Below is the step-by-step guide to Connect Your Instagram Account to a Facebook Page. To run ads on Instagram via Ad Manager, you must connect your Instagram Business Account to your Facebook Page. Once the Instagram account is connected to Facebook page, it will automatically be selected whenever tAd Manager
- How to create a Facebook form in Ad ManagerIn this article we will discuss in detail about the steps to be taken to create a new Facebook lead form, used for the Lead Generation objective of Meta ads. TABLE OF CONTENTS - How to create new Facebook Form? - How to use custom fields in Ad Manager? - How to review, map and duplicate existing FaAd Manager