Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
Well, so I am going to follow your advice and group the data in Google Analytics. Thank you, guys! –  pelegrini May 25 '12 at 23:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.