: 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
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?
More posts by @Turnbaugh106
1 Comments
Sorted by latest first Latest Oldest Best
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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.