Mobile app version of vmapp.org
Login or Join
Turnbaugh106

: Is it possible to change URL structure and to continue to gather Analytics data to the existing posts? I'm changing my WordPress permalinks from /%category%/%post_id%/ to /%postname%/ Is is possible

@Turnbaugh106

Posted in: #GoogleAnalytics #Permalinks #Wordpress

I'm changing my WordPress permalinks from

/%category%/%post_id%/


to

/%postname%/


Is is possible to make Google Analytics to continue gathering the posts data correspondingly?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Turnbaugh106

1 Comments

Sorted by latest first Latest Oldest Best

 

@Angie530

Yes, it is possible, but you would need to alter the way your Google Analytics tracking script behaves and, in the long run, your analytics data would not map directly to your site's URI structure (which may compromise the usefulness of your analytics reports).

Your revised Google Analytics snippet would look something like this:

<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);

<?php if ( is_single() ): ?>
_gaq.push(['_trackPageview', '/<?php $cat_list = get_the_category(); $cat = $cat_list[0]; echo $cat->slug; ?>/<?php the_ID(); ?>']);
<?php else: ?>
_gaq.push(['_trackPageview']);
<?php endif; ?>


(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

</script>


As stated above, you probably won't be happy with the results in the long run if you implement this workaround, however, you may want to familiarize with the WordPress Codex and the WordPress StackExchange site if you would like to learn more about modifying how your blog behaves.

The example above also makes use of Virtual Pageviews in Google Analytics.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme