Do not use blank "campaignId" strings with Google Analytics tags

blank string
Recently, I encountered this curious problem with a client's Google Analytics Source/Medium report: the top Source/Medium by sessions was "(not set) / (not set)". This was very, very unusual. What could possibly cause GA to not recognise Source/Mediums correctly?

The short answer was that a blank string had been set as the "campaignId" in the GA tags. Since GA couldn't interpret the blank string, it simply saved the Source/Medium as "(not set) / (not set)".

Special thanks to Jason Packer (@jhpacker in measure.slack.com) for his help here.


This client had a unique way of tracking traffic from campaigns. Instead of adding GA's usual utm_source, utm_medium, utm_campaign, utm_content and utm_term (a.k.a. "UTM tags") to their landing page URLs, the client used a single campaign tracking code. This was inherited from another analytics tool's convention of tracking campaign traffic.

To track the single campaign tracking code in the GA tags, the client made use of GA's relatively unknown "campaignId" field. Through the client's Google Tag Manager, the single campaign tracking code was tracked like this:
  1. Read the single campaign tracking code from the landing page URL into a GTM variable.
  2. Use that GTM variable with the "campaignId" field in all GA tags.
But what if the landing page URL didn't have the single campaign tracking code? This would happen when the user entered the site without going through a campaign. For example, when the user typed the URL directly, or when he arrived through an organic search result, then there wouldn't be any campaign tracking code in the page's URL.

The underlying assumption with how GTM variables work is that when the GTM variable does not have a value, then GTM does not set the corresponding field in the GA tag.

For example, let's say a GA tag has Custom Dimension 3 set to a variable, which itself is set from the value of a cookie. But if the user's browser doesn't have that cookie, then the GTM variable gets a blank value, and GTM will simply not set Custom Dimension 3 in the GA tag.

That should have worked with our "campaignId" field too, in the case when the user's landing page URL did not have the single campaign tracking code. But it turns out that GTM didn't follow this assumption.

When the landing page URL did not have the single campaign tracking code (e.g. the user entered the site from an organic search result), GTM would detect a blank string as the single campaign tracking code – and pass it on to GA's "campaignId"!

When GA receives a hit containing a UTM tag or a "campaignId" field, it uses that information to set its Source/Medium report. An explicit campaign tag always overrides the default way of using the browser's referral string, which is how direct traffic, organic search and referrals are tracked.

When GA received these blank string "campaignIds", it didn't know how to deal with them. So it used its default – but not very helpful – "(not set) / (not set)" with the Source/Medium!

So the final solution for the client was this:
  1. Remove the "campaignId" field from all GA tags.
  2. Use GA's UTM tags only to track campaigns.
  3. If the single campaign tracking code must be tracked, then track it to a Custom Dimension instead.
After the fix to remove the "campaignId" field, the client's Source/Medium reports started looking as they had expected. Where "(not set) / (not set)" used to account for almost 90% of their sessions, it was now about 12% – and dropping. Meanwhile, sessions from Direct and Organic Search rose from 4% to a more "normal" 76%.

"I've got a blank string, baby,
And I'll write your name."
~ Taylor Swift, "Blank Space" ~


Special thanks to Jason Packer (@jhpacker in measure.slack.com) for his help here.

References:

Comments

Popular posts from this blog

How to "unpivot" a table in BigQuery

Adobe Analytics and Google Analytics terminologies cheat sheet

Querying Google Analytics data as flat tables from BigQuery: The Definitive Guide and Recipe