We’re pretty obsessed with putting UTMs on f*cking everything. But what happens when you have inbound traffic from links you can’t control? Here’s how we re-write parameters on the fly, in this case for SalesLoft emails (because no Sales rep or BDR is going to use the UTM spreadsheet).
We recently worked with a client who wanted to attribute any/all traffic coming from SalesLoft in Google Analytics. Thankfully SalesLoft always appends a sbrc parameter to links in SalesLoft emails when Live Website Tracking is enabled for the domain of the destination URL. So,
In Google Tag Manager, I created a custom variable to check if the parameter sbrc is present in the query string.
If so, before we send our hit to Google Analytics, we’re going to set or override some UTM parameters before hitting Google Analytics servers. In essence, we’re saying, “I know this visit is from SalesLoft, therefore modify the utm_medium and utm_source to email and salesloft, respectively.”
Voila! As far as Google Analytics is concerned, that’s the actual URL that somebody hits.
IMPORTANT: for this to work, you must deploy Google Analytics through Google Tag Manager.
Step-by-Step
Create a new custom variable called sbrc. For the variable type, select URL. Under Component Type, choose Query. For Query Key, type sbrc. This will set the variable equal to the value of the sbrc query string parameter.
Create another custom variable called utm_medium using the same values as above, except this time, set Query Key = utm_medium.
Repeat the previous step for utm_source, utm_campaign, utm_term, and utm_content.
Next, we’ll create a new custom variable of type Custom Javascript called utm_medium Modified. Copy and paste the following:
function(){
var medium = {{utm_medium}};
if ({{sbrc}}) {
medium = "email";
}
return medium;
}
This code checks to see if the custom variable sbrc that we defined in Step 1 has a value. If so, it sets the value of utm_medium Modified equal to “email” (because we know this traffic is from SalesLoft), otherwise, the value will be equal to the original utm_medium value. Most likely, this is probably null, but we would override any value that may have been set.
Create another Custom Javascript variable called utm_source Modified and copy and paste the following code:
function(){
var source = {{utm_source}};
if ({{sbrc}}) {
source = "salesloft";
}
return source;
}
In your Google Analytics tag, select your Google Analytics Settings variable, and add the following Fields to Set: Here, we’re setting the values for campaignMedium, campaignSource, campaignName, campaignContent, and campaignKeyword equal to our custom variables utm_medium Modified, utm_source Modified, utm_campaign, utm_content, and utm_term, respectively.
Save and publish your Google Tag Manager version, and start seeing SalesLoft traffic categorized appropriately in Analytics!
Notes:
You must add subdomains as separate domains when configuring your Live Website Tracking in SalesLoft as they treat example.com and www.example.com as separate domains. Make sure you add any and all subdomains you want tracked to this list.
This will only apply to traffic going forward and will NOT update historical traffic retroactively.