1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Google Analytics Code Change

Discussion in 'XenForo Suggestions' started by piepo, Jul 22, 2015.

  1. piepo

    piepo Member

    Hey guys,

    In Germany we need to modify the GA tracking code to anonymize the IP addresses of our vistors. If we don't use that code we may get in trouble with the authorities.

    The functions name is anonymizeIp

    Code to be inserted for Universal Analytics is

    HTML:
    <script>
    
    (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-XXXXXXX-X', 'website.de');
    ga('set', 'anonymizeIp', true);
    ga('send', 'pageview');
    
    </script>
    For the classic version:

    HTML:
    <script type="text/javascript">
    
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-XXXXXXX-X']);
    _gaq.push(['_gat._anonymizeIp']);
    _gaq.push(['_trackPageview']);
    
    (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
    
    </script>
    I know that the German customers are a minority compared to the customer base you have but it shouldn't be hard to offer this modification by setting in the ACP

    Thanks
     
  2. piepo

    piepo Member

    Furthermore an OptOut Cookie solution is required

    Code:
    <script>
    jQuery(document).ready(function(){
    jQuery('#GAOptOut').click(function() {
        gaOptout();
        GAOptOutFeedback ();
    })
    if (document.cookie.indexOf(disableStr + '=true') > -1) {
        GAOptOutFeedback ();
    }
    function GAOptOutFeedback () {
        jQuery('#GAOptOutBr').before(navigator.appName+'-');
        jQuery('#GAOptOutDom').after(': <a href="'+window.location.origin+'">'+window.location.origin+'</a>');
        jQuery('#GAOptOutFeedback').remove();
        jQuery('#GAOptOut').after('<span id="GAOptOutFeedback" style="color:#FF0000"> (Status: Opt-Out-Cookie is in place)</span>');
    };
    });
    </script>
     
    rike-online, Alluidh, kailew and 2 others like this.
  3. piepo

    piepo Member

    Too bad that nobody replies on a reqiured code change for customers who do use XF in Germany.
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    Suggestion threads aren't usually commented on routinely.

    We haven't really received any amount of feedback to suggest this is something we need to implement as a priority. I would have expected more feedback by now if this was going to be affecting all German customers and their members (of which I am sure there are many).

    In the meantime I can only suggest making the code change yourself directly.
     
  5. piepo

    piepo Member

    This really is a requirement for using GA.

    As an admin you have to sign a contract and send it to Ireland having them to confirm and send it back..

    Cannot comment on the # of answers but this is a must and shouldn't be that hard to make it in a 1.5.1 as an option?

    Re: Code Change myself

    In the core files you mean?
    Would do it in a template?
     
  6. Chris D

    Chris D XenForo Developer Staff Member

    The difficulty of such a change isn't in question. The necessity of such a change is the main issue. So far we've been told this is a requirement for everyone in Germany by one customer (potentially a second if you count the "Like" on the first post). We don't really currently have sufficient information to understand why this is a necessity or how crucial it is.

    To change it yourself you just need to modify the google_analytics template.
     
  7. piepo

    piepo Member

    For the records.

    Your google_analytics template should look like

    Code:
    <xen:if is="{$xenOptions.googleAnalyticsWebPropertyId}"><script>
    
    var gaProperty = 'UA-XXXXXXX-X';
    var disableStr = 'ga-disable-' + gaProperty;
    if (document.cookie.indexOf(disableStr + '=true') > -1) {
      window[disableStr] = true;
    }
    function gaOptout() {
      document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
      window[disableStr] = true;
    }
    
    </script>
    <script>
    
    (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-XXXXXXX-X', 'example.com');
    ga('set', 'anonymizeIp', true);
    ga('send', 'pageview');
    
    </script></xen:if>
     
    Alluidh likes this.
  8. piepo

    piepo Member

    Entering the GA-ID in the XF settings is still fine with that code?

    Just to make sure.
     
  9. Tracy Perry

    Tracy Perry Well-Known Member

    Modify the google_analytics to be what you need (the example that they give you) and you should be fine. That is what I had to do when I changed over to the newer style GA before XF implemented it.
     
  10. Adan0s

    Adan0s Member

    German User here. Theoretically it's an necessity which every german website owner has to abide: https://www.huntonprivacyblog.com/2...ful-in-germany-subject-to-certain-guidelines/, http://www.iubenda.com/blog/2013/11/13/ip-anonymization-google-analytics-privacy/
    Just like providing the option to opt-out of analytics and the notorious EU-Cookie law.
     
  11. kailew

    kailew Member

    This is still a requirement for german users and that there aren't more here shouldn't be regarded as lack of interest. There could be different reasons, one of them is that this board is in english ... I also think that it would be no big work to integrate this into acp.
     
  12. snoopy5

    snoopy5 Well-Known Member

  13. kailew

    kailew Member

    That only one custumer told you about the requirement may have some reasons:
    - language problems
    - many customers may not know that this is necessary
    - there aren't any current problems with the greedy lawyers, but this could happen every day, but than it's too late!
    It may happen one day, that your customers have to pay fees for "Abmahnungen" which could be between 1000-2000 Euro per issue. This is still a risk for everybody who uses the wrong code.

    The fact is: It is german and european law which google also knows, so there is no reason to change it not in admincp.

    Kai
     
  14. snoopy5

    snoopy5 Well-Known Member

    Since this is a suggestion forum and i do not know how closely this is watched, I bookmark it for you, so that you do not miss this...

    @Kier
    @Brogan
     

Share This Page