Insights

How to Alter Your Campaign Values Using Google Tag Manager

Campaign tagging is an important aspect of your analytics setup. It’s one of the critical elements in reducing your dark traffic. But sometimes, the tags on the url don’t pull into Google Analytics perfectly, and require a little finesse on the back end to populate your reports properly.

For example:

  1. You want to promote a Facebook post that you previously tagged as unpromoted, but want to add additional campaign tags to indicate you’ve paid to promote it.
  2. You have a set of links that have campaign parameters built for another secondary system, and you don’t want to (or can’t) add additional utm parameters to get that same data into GA.
  3. You have nondescript campaign tags that you want to make human-readable in reports.

Fortunately, Google Tag Manager (GTM) gives you the ability to change all of these. The trick is to update your Pageview Tag in GTM with these Fields to Set:

  • campaignMedium
  • campaignSource
  • campaignName
  • campaignContent
  • campaignKeyword

For all of these scenarios, you set these 5 fields in your Pageview Tag, and set a variable to change it as needed.

Scenario 1: Facebook Post Unpromoted to Promoted

You want to promote a Facebook post that you previously tagged as unpromoted, but want to add additional campaign tags to indicate you’ve promoted it.

First, you’re tagging all your Facebook posts even if you don’t promote the post, right? It probably looks something like this:

http://www.mysite.com?utm_source=facebook&utm_medium=social&utm_campaign=cool-stuff&utm_content=testimonial

It’s doing pretty well so a few days later, when you go to promote it, you realize you can’t change the existing link -- but you CAN add an additional parameter, which you do:

http://www.mysite.com?utm_source=facebook&utm_medium=social&utm_campaign=cool-stuff&utm_content=testimonial&utm_term=paid

However, in GA you’d have to pull in the keyword dimension to distinguish these two. So let’s rewrite this in GTM so your campaign medium comes in as paid-social when the utm_source is facebook and utm_term is paid.

Step 1: Put all the utm_parameters into Variables

  1. Create a new variable type URL
  2. Set the Component Type to Query
  3. Set the Query Key to the corresponding query (example below, utm_campaign)
  4. Repeat this process to create all 5 variables for each corresponding campaign value

Your completed variables should look like this.

Step 2: Create a Variable that Modifies the Medium

  1. Create a new variable, type Custom JavaScript
  2. Write your javascript to rewrite when you’re conditions are met. When term is paid, and medium is social, and the source is facebook, rewrite the medium to paid-social. For the example above, you can use this snippet (note this is if each of your campaign variables are named similar to the utm_campaign example above):

/*Rewrite the medium to paid social when conditions are met */

function(){ var medium = ; if ( == "paid" && medium == "social" && == "facebook") {   medium = "paid-social";     } return medium; }

Step 3: Create/Update Your Pageview Tag Setting Campaign Data

  1. Create or edit your Pageview tag
  2. Under More Settings > Fields to Set, set each of the 5 campaign fields (also noted above)
    1. campaignMedium - use your modified variable
    2. campaignSource - use your URL query variable
    3. campaignName - use your URL query variable
    4. campaignContent - use your URL query variable
    5. campaignKeyword - use your URL query variable

Now preview, test, and publish. You’ll see traffic to this url:

http://www.mysite.com?utm_source=facebook&utm_medium=social&utm_campaign=cool-stuff&utm_content=testimonial&utm_term=paid”  

appear as a medium of paid-social along with your other paid social traffic.

*Note this was written before the Google Analytics Settings Variable came out. These same settings can be done in that variable instead.

Scenario 2: Using a different campaign parameter

For some reason you don’t use Google’s utm parameters, but have custom parameters you’d prefer to use instead.

For example, your email program adds their own campaign parameter (for example, emailname) for their own tracking purposes to all links. You want to add GA parameters, but you also want to pull the emailname parameter into your campaign tag.

Your tagged links look something like this:

http://www.mysite.com?utm_source=internal&utm_medium=email&emailname=july-monthly

However, in Google Analytics, you want the Campaign name to be populated with what is in emailname. So let’s rewrite the campaign name value, but ONLY when the emailname parameter is present.

Step 1: Put all the utm_parameters into Variables

  1. Create a new variable, type URL
  2. Set the Component Type to Query
  3. Set the Query Key to the corresponding query
  4. Repeat this process to create all 5 variables for each corresponding campaign value (see step 1, scenario 1)
  5. Create a 6th variable type URL for your custom campaign variable (example below, utm_campaign)

Step 2: Create a Variable that selects which Campaign Value to use

  1. Create a new variable, type Custom JavaScript
  2. Write your javascript to return the emailcampaign value when present, or the utm_campaign value when it’s not. For the example above, you can use this snippet (note this is if each of your campaign variables are named similar to the utm_campaign example above):

/*Return the campaign email campaign variable when available or regular campaign variable when not */

function(){ var emailcampaign = || ;  return emailcampaign; }

Step 3: Create/Update Your Pageview Tag Setting Campaign Data

  1. Create or edit your Pageview tag
  2. Under More Settings > Fields to Set, set each of the 5 campaign fields (also noted above)
    1. campaignMedium - use your URL query variable
    2. campaignSource - use your URL query variable
    3. campaignName - use your modified campaign selector variable
    4. campaignContent - use your URL query variable
    5. campaignKeyword - use your URL query variable

Now preview, test, and publish. You’ll see traffic to this url:

http://www.mysite.com?utm_source=internal&utm_medium=email&emailname=july-monthly

Appear as a campaign name of july-monthly directly in your campaign reports.

Scenario 3: Rewrite nondescript campaign tags

The names you want to use for your campaign information aren’t something you want visible in your URLs.

For example, you want emails with links that address different types of issues for a customer to be tagged, but don’t want display how they’ve been tagged to the customer.

Your tagged links look something like this:

http://www.mysite.com?utm_source=customer-service&utm_medium=email&utm_campaign=rpt

However, when pulling your reports, you’d prefer not to have to look up what the campaign code “rpt” means. So, let’s use a lookup table in GTM to rewrite these codes.

Step 1: Put all the utm_parameters into Variables

  1. Create a new variable, type URL
  2. Set the Component Type to Query
  3. Set the Query Key to the corresponding query
  4. Repeat this process to create all 5 variables for each corresponding campaign value (see step 1, scenario 1)

Step 2: Create a Variable that selects which Campaign Value to use

  1. Create a new variable type Lookup Table
  2. Set your input variable to your campaign variable
  3. Create your lookup table with the codes for Input and the readable version in Output
  4. Set Default Value to your campaign variable . This is important so other tags that are not coded will still be set properly.

Step 3: Create/Update Your Pageview Tag Setting Campaign Data

  1. Create or edit your Pageview tag
  2. Under More Settings > Fields to Set, set each of the 5 campaign fields (also noted above)
    1. campaignMedium - use your URL query variable
    2. campaignSource - use your URL query variable
    3. campaignName - use your Lookup Table modified variable
    4. campaignContent - use your URL query variable
    5. campaignKeyword - use your URL query variable

Now preview, test, and publish. You’ll see traffic to this url:

http://www.mysite.com?utm_source=customer-service&utm_medium=email&utm_campaign=rpt

Appear as a campaign name of instructions-help directly in your campaign reports.

A Few Final Tips for Changing Campaign Tagging in GTM

  • If you choose to manually set/modify one of the five main campaign parameters, in your GTM pageview tag, set them all. This avoids campaign tagging breaking for the other parameters.
  • When testing any modification to campaign values, make sure that you test not only the rewrite, but other variations that you wouldn’t want rewritten including manual tags and clicking on an organic link, to make sure nothing is inadvertently removed.

The three scenarios outlined are just examples, your cases may vary. If you take this blog post to modify your campaign variables in a different way tell me about it in the comments.

SIGN UP FOR NEWSLETTER

We love helping marketers like you.

Sign up for our newsletter for forward-thinking digital marketers.

Michelle Noonan
Michelle Noonan
Sr. Lead, Digital Measurement Solutions