Welcome to Julian Kuiters Saturday, August 18 2018 @ 05:12 PM AEST

Google Analytics code in Business Catalyst Website

  • Contributed by:
Adobe Business Catalyst

Business Catalyst already includes a great reporting tool - but Google Analytics is still my prefered report engine. You can gain so much information about who and why people are visiting your business catalyst site - more importantly it can help you figure out why sales or contact forms are not being completed.

Eventually this page is going to hold all the tips I have about using Google Analytics with Business Catalyst, but for now I have one tip and that is how to add the analytics tracking code to your templates in a way that works with Business Catalyst and the Dreamweaver plugin Triangle.

Business Catalyst (BC) has a habit of decoding the tracking code and breaking it. (Those "%3C" you see in the google code are actually "<"  but they need to be encoded to work).

The problem comes in with this part of the tracker code:

<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"));

Notice the unescape() call - this is what tells the browser to decrypt the %3C - BC should not touch this - but it does.

So the work around I have been using is:

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write("<scr" + "ipt src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'></scr" + "ipt>");

Notice that I've pre-decoded the string, removed the call to unescape() and broken up the string.

The important part here is that you must break up the <script  tag into something like <scr" + "ipt  ... this stops the webbrowser from seeing the script tag until the javascript tells it to (with the document.write() ). If you skip this bit you google analytics code will still not work and you will probably get javascript errors on the page.