Search code examples
google-analyticsquery-stringaffiliateutm

Turn affiliate query parameter "r" into UTM tags on Google Analytics


I have people referring traffic to my website using a URL like this:

domain.com?r=1234

Each affiliate has a unique "r" code. How can I detect the query parameter "r" on the pageview of my website and translate it into a set of UTM tags that can be detected by Google Analytics, so that I can see which users are doing what on my Google Analytics reports? The mapping would be something like this:

If URL contains ?r=1234 -> Send to Google Analytics as ?utm_medium=referral&utm_campaign=1234

The idea is being able to see the traffic coming thanks to these affiliates together with the rest of the traffic coming from other medium/campaigns (using UTM tags) and have the option to filter by medium or campaign on Google Analytics, so I guess the only way is turning the "r" query parameter into UTM tags. However, I'm open to other solutions. Thanks a lot!

Edit: At the moment, I'm able to capture the "r" query parameter using Google Tag Manager. As I'm tracking the pageviews and other goals using Google Tag Manager, the idea would be attaching the parameter "r" somewhere within the tag, so that Google Analytics detects it. Or something equivalent.


Solution

  • You can use UTM directly and share a short URL generated i.e. with a online service. Anyway you have to add utm_medium because it is mandatory, and referral is medium not source.

    You can also override source / medium / campaign value forcing them in page or via GTM.

    i.e. based querystring parameter you can configure GA tag similar to this (where variables values will be what you want):

    enter image description here