Tagged: code, functions.php
-
AuthorPosts
-
May 26, 2023 at 5:34 pm #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/”;
_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>
<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.May 27, 2023 at 3:45 am #1408741Hi 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,
NikkoMay 27, 2023 at 1:50 pm #1408779When 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!
May 27, 2023 at 8:04 pm #1408812Hi,
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,
RikardMay 28, 2023 at 2:19 pm #1408863Oke than kyou Rikard, that’s just what I wanted to check :)
Best Wishes,
AlwinMay 28, 2023 at 3:13 pm #1408868Hi,
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 -
AuthorPosts
- The topic ‘Code in functions.php ?’ is closed to new replies.