Web analytics

Forwarding UTM parameters from the landing page to another domain.

The client had several one-time landing pages on different domains and wanted to drag traffic to their main website through them. These landing pages did not contain any form, only links to the purchase process on another domain. So evaluating the benefits of individual campaigns was quite a problem, because the data was in several Google analytics properties (services) and the result was only a newsagent from the landing page, but it was no longer possible to link the campaigns to meeting the goals on the main site. For some special reasons, the classic cross domain could not be used.

And that’s why I got the idea to pass UTM parameters to the main site for such simple landing pages.

What does the script do?

The script goes through all the links on the given page and if it finds a link to the main website and it no longer has UTM parameters, then it adds modified UTM parameters through which the visitor came to the given landing page.


I will come to the page with UTM parameters… = campaign-name&utm_term = key-phrase&utm_content=nice-banner

The page has a link:

After running the script, it is adjusted to:

Script features:

  • The script modifies the parameters UTM source and UTM medium, the rest is forwarded without changes. This makes the forwarded traffic known sufficiently recognizable. I am modifying Utm_medium to know that I will not have Google ads ets in this GA for this advertising spend.
  • I added a cookie that will hold UTM for 30 minutes even if the user loses UTM parameters from the URL due to walking through those few microsite pages. This solves the problem of 2-3 pages on the microsite to promote UTM there as well. Limit 30min classic length of GA visit.
  • It is also set there so that UTM parameters are not overwritten if they are already in the URL. So it can be run multiple times and nothing happens.
  • The target domain is set in the script, the URL can also be given there;). So that UTM parameters are not forwarded to places you do not want.

When will it not work?

You use autotagging via gclid in Google ads, so you don’t have the classic UTM parameters in the URL. But it can be bypassed through manual tagging, here you can also put variables such as the name of the campaign, etc. making such manually automated.

What doesn’t it solve?

Organic, I take it as if it is correct if the link remains without modifications and the main page will be a newsagent as a referral given the landing page.

When should you definitely not use it?

If the landing page is on the same domain as the main site. In that case, you should have the same Google analytics ID and not solve anything like that.


In the Google tag manager, insert the following script into the tag and edit the value of “targetdomain” on your main site.

function getCookie(a) {
    var b = document.cookie.match('(^|;)\\s*' + a + '\\s*=\\s*([^;]+)');
    return b ? b.pop() : '';

(function () {
    var cookieminutes = 30; 
    var targetdomain = "";
    var params = new URLSearchParams(;
    var utm_params = [];
    params.forEach(function(value, key) {
        if (key.startsWith('utm_')) {
             if (key=='utm_medium'){utm_params.push(key+'=bypass-'+value)}
             else if (key=='utm_source')
             else {utm_params.push(key+'='+value);}  }      
    utm_search = utm_params.join('&');
    if (!utm_search) // get values from backup cookie
        var utm_search = getCookie("utm_bypass");
    if (!!utm_search) {
        // cookie backup for reload
        var d = new Date();
        d.setTime(d.getTime() + (cookieminutes * 60 * 1000)); // cookie backup
        var expires = "expires=" + d.toUTCString();
        document.cookie = "utm_bypass" + "=" + utm_search + ";" + expires + ";path=/";

        // links update
        document.querySelectorAll('a[href]').forEach(function (ele, idx) {
            if ((ele.href.indexOf(targetdomain) !== -1) && (ele.href.indexOf("utm_") == -1)) {
                ele.href = ele.href + (ele.href.indexOf('?') === -1 ? '?' : '&') + utm_search;

When to run the script?

In the Google tag manager for the DOM ready event. The page will already contain links that can be modified. For a SPA application, the script would go a lot when changing the url / content.
The script does not use any GTM functions, so it can be inserted at the end of the page manually into the code.