Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1408717

    Hello, just asking to be sure:

    Can I include both Google Analytics code and PiwikPro code in my functions.php like this:

    function piwik_analytics_header(){
    ?>
    <script type=”text/javascript”>
    var _paq = _paq || [];
    _paq.push([“setTimingDataSamplingOnPageLoad”, 100]);
    _paq.push([“trackPageView”]);
    _paq.push([“enableLinkTracking”]);
    (function() {
    var u = “https://xxxxxxxxxxx.piwik.pro/&#8221;;
    _paq.push([“setTrackerUrl”, u + “ppms.php”]);
    _paq.push([“setSiteId”, “xxxxxxxxxxxxxxxxxxxx”]);
    var d = document,
    g = d.createElement(“script”),
    s = d.getElementsByTagName(“script”)[0];
    g.type = “text/javascript”;
    g.async = true;
    g.defer = true;
    g.src = u + “ppms.js”;
    s.parentNode.insertBefore(g, s);
    })();
    </script>
    <?php
    }
    add_action(‘wp_head’, ‘piwik_analytics_header’);

    function google_analytics_header(){
    ?>
    <!– Google tag (gtag.js) –>
    <script async src=”https://www.googletagmanager.com/gtag/js?id=G-xxxxxxxxxxxxxxxx”></script&gt;
    <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag(‘js’, new Date());

    gtag(‘config’, ‘G-xxxxxxxxxxxxxxx’);
    </script>
    <?php
    }
    add_action(‘wp_head’, ‘google_analytics_header’);`
    `

    Two analytics services in my functions.php like this aren’t going to conflict with each other?
    Seems to me it’s working fine, but like to be sure.

    #1408741

    Hi Alwin,

    Can you try to remove those PHP codes so only the script tag remains?
    Try to remove the following in your code:

    function piwik_analytics_header(){
    ?>
    <?php
    }
    add_action(‘wp_head’, ‘piwik_analytics_header’);
    
    function google_analytics_header(){
    ?>

    and

    <?php
    }
    add_action(‘wp_head’, ‘google_analytics_header’);

    Hope it helps.

    Best regards,
    Nikko

    #1408779

    When I remove those code then I only have the piwikpro and GA code left? I have to place them in the header using the code that you say I should delete? I don;’t understand, sorry…

    It seems to be working fine with my code!

    #1408812

    Hi,

    Thanks for the update. I’m not really sure I understand exactly what you need help with, but if the code you posted in your initial post is working, then I don’t see any problem with using it.

    Best regards,
    Rikard

    #1408863

    Oke than kyou Rikard, that’s just what I wanted to check :)

    Best Wishes,
    Alwin

    #1408868

    Hi,
    Glad Rikard could help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.

    Best regards,
    Mike

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Code in functions.php ?’ is closed to new replies.