Custom Code

Getting Google Analytics to Work with ServiceNow CMS

Everyone loves them some analytics, definitely brought up in every single conversation I have around CMS. ServiceNow does an okay job of providing some insight, but it’s not usually to the level that people want or expect from a front-end website.

Enter Google Analytics (or GA if you’re hip with it).There are a few things that make GA a no-brainer choice for your CMS:

  • It’s free. Seriously.
  • It’s simple to add. You snag your analytics code snippet from your GA account for that property and then copy it right into your Layout. It will then render on every single page on your CMS site. 5 minutes max.
  • You get great insight into how people are flowing through your site, how many people are currently on or have visited your portal, which pages they’re going to the most, etc.

And here’s where the collision comes. You get your GA reports and all your pages have sys_ids in their URL so it’s a bit hard to just look at the URL and see which page is being reported on.

With a little bit of code you can fix this problem. This solution implies that you are using Content Types to render your Catalog and Knowledge articles. If you’re not, you just need to make sure you add the code to whatever page is calling those items.

We are going to add a script to the content type that grabs the specific values that we care about and then overwrite the “page title” value on the page. Being that content types render the page dynamically we don’t really have access to setting them at the true “page” level.

So here goes.

For the sc_cat_item content type, I include this anywhere on the detail template:

You can then change it to whatever values you want…for this example we are making sure the page title shows the Category and the Name of the Catalog Item.

For the kb_knowledge content type, it’s very similar, just different values:

You’ll notice on this one we’re bringing in a lot of info (Topic, Category, Title and KB Number). This way you can see the data however you care to see it.

The only other thing you have to do is enable the Page Title view in GA. To do this, go to your GA account: http://analytics.google.com (login), then navigate to > Behavior > Site Content > All Pages. In the “Secondary dimension” dropdown, go to Behavior > Page Title. It then shows the Page Title column next to the Page value. Done! The data you’ve been serving up will start to show. You can check this by going to Real-Time > Content.

Enjoy!

Leave a Reply