Do not use blank “campaignId” strings with Google Analytics tags

Sparkline were set with a curious challenge when one of our clients raised a problem with the Google Analytics Source/Medium report. The top Source/Medium by sessions was “(not set) / (not set)”. This was very, very unusual. We asked what could possibly cause GA to not recognise Source/Mediums correctly?

After some untangling, we discovered that the 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)”.

The client has a unique method 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, Sparkline made use of GA’s relatively unknown “campaignId” field. Through the client’s Google Tag Manager, we tracked the single campaign tracking code into GA 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 scenario could happen if the user enters the site without going through a campaign, for example, by typing the URL directly or through an organic search result.

The common thinking around how GTM variables work with GA tags is when the GTM variable does not have a value, then GTM does not set the corresponding field in the GA tag. For example, if the GA tag has Custom Dimension 3 and it is set to a variable, which is set from the value of a cookie. If the 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.

Our thinking was that this is how the “campaignId” field would be set as well. However, when the user’s landing page URL did not have the single campaign tracking code, it turns out that GTM didn’t follow this assumption.

When 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 “(not set) / (not set)” with the Source/Medium!

The Sparkline solution to this problem was:

  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 Source/Medium reports started looking as expected. Where “(not set) / (not set)” used to account for almost 90% of their sessions, now it’s about 12% and dropping. Meanwhile, sessions from Direct and Organic Search rose from 4% to a more “normal” 76%.

References: