• Resolved bady85

    (@bady85)


    Hello,

    thanks for your great plugin!

    Since the update from version 2.8.9 to the newest version I have a problem with the Google Analytics code.
    I use a consent which allows tracking with Google Analytics only if the visitor has agreed to it, for this reason my code looks like this:

    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async class="cmplazyload" data-cmp-vendor="s26" data-cmp-src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX">
    </script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
    
      gtag('config', 'G-XXXXXXX', { 'anonymize_ip': true });
    </script>

    Once I enable JS processing in FVM, the plugin does the following code on it:

    <script>
    window.dataLayer=window.dataLayer|[];function gtag(){dataLayer.push(arguments)}
    gtag('js',new Date());gtag('config','G-XXXXXXX',{'anonymize_ip':!0})
    
    </script>

    so it deletes the top line. When I remove the data-cmp-

    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async class="cmplazyload" data-cmp-vendor="s26" src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX">
    </script>

    GA works again, but this is critical from a data protection point of view. Is there a setting here that prevents FVM from deleting the line? I have tried all the checkbox combinations in JS processing so far.

    Thank you.

Viewing 1 replies (of 1 total)
  • Plugin Author Raul P.

    (@alignak)

    Hi,

    I’m not sure I understood, what top line is disappearing?

    Does `<script async class=”cmplazyload” data-cmp-vendor=”s26″ data-cmp-src=”https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX”&gt;
    </script>` disappear completely?

    If that is the case, it may be because the script has no valid src attribute.
    In that case, I suggest you change your markup to dynamically create the element based on your consent rule.

    For example, something like this, but wrapped under your condition:

    let script = document.createElement('script');
    script.src = "https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX";
    document.body.append(script);
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
    gtag('config', 'G-XXXXXXX', { 'anonymize_ip': true });
    
Viewing 1 replies (of 1 total)
  • The topic ‘Google Analytics with Consent not working’ is closed to new replies.