Forum Replies Created
-
AuthorPosts
-
TmasMember
I tried to set this code in Header and Footer scripts box
<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-XX', 'auto'); <?php if (is_single()){ echo "ga('set', 'contentGroup1', '".get_the_author()."');" \n"; $category = get_the_category(); if ($category && !empty($category[0]->cat_name)){ echo “ga(‘set’, ‘contentGroup2', ‘”.$category[0]->cat_name.”‘);” \n"; } } ?> ga('send', 'pageview'); </script>
But this is what I found in source code
(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', 'XXX', 'auto'); <?php if (is_single()){ echo "ga('set', 'contentGroup1', '".get_the_author()."');" n"; $category = get_the_category(); if ($category && !empty($category[0]->cat_name)){ echo “ga(‘set’, ‘contentGroup2', ‘”.$category[0]->cat_name.”‘);” n"; } } ?> ga('send', 'pageview'); </script>
So it doesn't handle PHP?
And if I added this same code in wp_head Hook, it doesn't print anything in source code.
And when I remove this part of code from wp_head Hook, then I can find Google Analytics code in source code.
I think that this php should have some error.
<?php if (is_single()){ echo "ga('set', 'contentGroup1', '".get_the_author()."');" n"; $category = get_the_category(); if ($category && !empty($category[0]->cat_name)){ echo “ga(‘set’, ‘contentGroup2', ‘”.$category[0]->cat_name.”‘);” n"; } } ?>
TmasMemberHi!
I found this code here:
https://www.highposition.com/blog/how-to-send-author-content-groups-wordpress-google-analytics/TmasMemberSo, here is the whole Google Analytics code which is in wp_head Hook.
<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-XXX', 'auto'); <?php if (is_single()){ echo "ga('set', 'contentGroup1', '".get_the_author()."'); $category = get_the_category(); if ($category && !empty($category[0]->cat_name)){ echo “ga(‘set’, ‘contentGroup2', ‘”.$category[0]->cat_name.”‘);”n”; } } ?> ga('send', 'pageview'); </script>
I hoped that this will print following code in source code.
<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-XXX', 'auto'); ga('set', 'contentGroup1', 'Author'); ga('set', 'contentGroup2', 'CategoryName'); ga('send', 'pageview'); </script>
But now my php does this that the whole Analytics code doesn't appear in the source code.
TmasMemberSorry but I don't understand what you mean. I hoped that this PHP print author and category name but it doesn't do anything.
-
AuthorPosts