How to print category name in source code
-
Hi!
I am adding Google Analytics Content Group in my blog.I added this kind of code in my Genesis blog using Hooks. PHP is allowed so this is not the problem.
<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()){ $category = get_the_category(); if ($category && !empty($category[0]->cat_name)){ echo “ga(‘set’, ‘contentGroup1', ‘”.$category[0]->cat_name.”‘);” \n"; } } ?> ga('send', 'pageview'); </script>This should print this kind of 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', 'Category's name'); ga('send', 'pageview'); </script>But id doesn’t work. If I have this php code with analytics code, then it doesn’t print whole analytics code. If I take php away, then rest of the code works well. I should have some basic problem in my PHP but what the problem is?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘How to print category name in source code’ is closed to new replies.