Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

Google Analytics and Hotjar

$
0
0

Replies: 0

Hey,

Thanks for the plugin.

Just want to make sure that I am doing the right thing. I am using google analytics and hotjar on my website. I have set up the cookies using the plugins settings.

I am using functions.php to right the code in my header section.

For google analytics the code I am using is:
(Note: This is pre-checked cookie that the user can uncheck.)

add_action( 'wp_head', 'google_opt_check');
  function google_opt_check(){
   if ( ! has_consent( 'analytics' ) || ! is_allowed_cookie( '_ga' ) ) {
    ?>
  <script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-XXXXXXX-X', 'auto');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<?php }};

For hotjar (note: this is unchecked cookie that the visitor can check)

add_action('wp_head', 'hotjar_opt_check');
function hotjar_opt_check(){
if ( ! has_consent( 'behaviour_analytics' ) ) {
?>
<script>
    (function(h,o,t,j,a,r){
        h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
        h._hjSettings={hjid:XXXXX,hjsv:X};
        a=o.getElementsByTagName('head')[0];
        r=o.createElement('script');r.async=1;
        r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
        a.appendChild(r);
    })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
</script>
<?php }};

Let me know if it makes sense.

Thanks in advance.


Viewing all articles
Browse latest Browse all 59525

Trending Articles