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


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:

  1. Run a Preview to verify it detects campaigns correctly

  2. Review logs to ensure no errors appear

  3. Complete the Authorization process

  4. 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.