Change/Append to UTM

Hi.

I’m trying to change the UTM values according to the variant of the page the user is in.

For example, if I send the user with utm_campaign=123 I would like that after the user submits the form, the utm_campaign became:

For variant A: utm_campaign=123_a
For variant B: utm_campaign=123_b

I’ve tried Googling the answer, but all I find is how to replace or add a UTM, never to append to an existing one.

Any help would be appreciated.
Thanks a lot

Hi @P_Fonseca1,

In your case replacement should work fine, you would want to just grab the original utm_campaign value as a variable and add the variant letter, then you would replace the utmCampaign field in google analytics with this variable.

This could all be achieved with GTM by:

  • Storing the utm_campaign as a variable (Query parameter).
  • Running a Custom Javascript variable that takes the value of the above and appends the variant letter.
  • Using a fields to set on a GA event triggered by Unbounce form submission that sets the value of campaignName to the value returned by you custom javascript variable.

I would however question whether this is truly the best way to go about getting the data you are after, why not have two campaigns each with their landing page set to the appropriate variant?

Anyway, I presume you have your reasons, but if you go down the data manipulation route, be sure to test thoroughly before messing around with your campaign attributions.

HI @Josh_berry-jenkins
Thanks for the reply!

Splitting the campaign doesn’t achieve the same result, as what I’m trying to assess here is the medium term behaviour/engagement from the users after having signed up from variant A/B/N - that’s why I need to store the variant letter to identify them, but it needs to be a true random split of traffic, not pre-defined.

Would you know if that’s accomplishable using JS directly on page, rather than resorting to GTM?

Thanks again for your help

Okay, fair enough.

What about setting a custom dimension in GA to indicate the most recent variant they converted from?

This way you could build a custom report or use secondary dimensions to segment users beyond just session landing page.

Either way, yes, both could be achieved via javascript on the page, but it would depend on your analytics setup (gtag or analytics.js) and your confidence in editing the GA tracker object (Developer Territory Warning).

The Analytics documentation is (surprisingly) actually quite decent if you are willing to look into it:
https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#campaignName
https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets

I appreciate your help @Josh_berry-jenkins

I’m actually trying to achieve something that’s separate from GA. We store the UTM values of each sale on our database, and that’s why I’d need those to have the appended value.
I’ll try to figure out how to replace/append this value to the UTMs some other way.

Thanks again

Hi @P_Fonseca1, I did something like this a very long time ago.

If all you’re interested in doing is saving the campaign and variant to your database, you can access the Unbounce variant using ub.page.variantId.

See this thread on how to push this into the database - Get variant name in report and or GTM

It’s not quite the full story (doesn’t deal with getting the campaign name from the query param, but that’s not hard), but is hopefully a push in the right direction.

FWIW, overwriting UTMs is a bit of an antipattern - I’d create a new custom one called utm_variant or something, then the campaign is always intact :slight_smile: