Jan 14, 2010
My Digital Life Editorial Team

How to Add Google Analytics Tracking Code in vBulletin 4

When adding or inserting Google Analytics tracking code in vBulletin 4 forums software, either in styles, templates, plugins, products or ad HTML code of newly added advertising function, error message similar to the following may appear when saving the code:

The following error occurred when attempting to evaluate this template:

Parse error: syntax error, unexpected ‘[‘
in /home/forums/includes/adminfunctions_template.php(4595) : eval()’d code on line 18

This is likely caused by a malformed conditional statement. It’s highly recommended that you fix this error before continuing, but you may continue as-is if you wish.


Two options of “Go Back” or “Continue” are available for user selection. And of course, even if user forcefully save and make active or enable the Google Analytics tracking code, the script doesn’t work, and does not appear on web pages.

Google Analytics tracking code or script contains some special characters which does not parse properly. Thus, in order to embed Google Analytics tracking code, the easier way is to wrap the code with <vb:literal> and </vb:literal> tags so that the code is treated literally during page rendering.

For example,

<vb:literal>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">\>
try {
var pageTracker = _gat._getTracker("****");
pageTracker._trackPageview();
} catch(err) {}</script>
</vb:literal>

The Google Analytics tracking code can be placed in footer template, or better suggestion is to place it into ad_footer_end template (inside Ad Location Templates) as to avoid future upgrading issues where templates need to manually merged.

Related posts:

  1. Use {Literal} Smarty Tag to Add Google Analytics Tracking Code to BlogSome Hosted Blogs
  2. Google Analytics for Mobile Server-Side Tracks Mobile Phone and PDA Devices
  3. WordPress Plugin: Display Google Analytics and FeedBurner Reports Statistics from Site Admin
  4. Official Google Analytics Blog Offers Tips and Information
  5. How to Remove or Delete (Unlink) Google AdSense and Analytics Integration

9 Comments

  • I liek turhtels

  • Worked a treat. Much like the literal php tags.

  • Thanks. its working :)

  • thank you. this is good tips for me.

  • Thanks, very helpful

  • Thanks for the help

  • Thanks, it works for the forums.

  • Same here, you saved the day!

  • Thanks for the post, could not find the answer at vbulletin.org. Worked like charm.

Leave a comment

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Subscribe

Free email subscriptions
Get latest updates in email for free:

Translate This Page