How to exclude payment method as referral in Google Analytics, through code?

后端 未结 1 1347
隐瞒了意图╮
隐瞒了意图╮ 2021-01-29 03:37

My payment gateways show up as referrals in Google Analytics. I\'ve read a bit about it, and it looks like there are two options to fix this:

  1. Adding an entry to th
相关标签:
1条回答
  • 2021-01-29 04:29

    No idea if this has any side effects, but the following seems to work: Universal Analytics has a "set"-method that allows you to override fields before they are send to the server. So you can override the referrer field and set it to some domain that's already part of your referral exclusion list.

    So if you want to keep the utm_nooverride parameter you could do something like:

    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
            m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
    
    ga('create', 'UA-XXXXXX-XX', 'auto');
    if(location.search.indexOf('nooverride') > -1) {
        ga('set', 'referrer', 'yourdomain.com');
    }
    ga('send', 'pageview');
    

    If the query string contains "nooverride" (of course you can choose any other name for the parameter) the referrer is set to the name of your domain, and your domain is (or at least should be) already part of your referral exclusion list.

    You might want to test this more extensively, but it worked for me when I whipped up a test page for this question so it should be worth exploring.

    0 讨论(0)
提交回复
热议问题