I am using this 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-xxxxxxxx-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>
The aim is here to send both the category name and author from my Wordpress website to Google Analytics (Content Grouping).
However, when my website is being viewed my source code (in the head section) still shows the php tags. How can I ensure that the PHP code is properly parsed and the author / category information is correctly inserted?