The Silver Lining

Lessons & Learnings from a salesforce certified technical architect.

Salesforce: Force.com Sites and Google Analytics

with 3 comments

This is a cross-post from the Tquila blog.

My Favourite Chart Type

Not having analytics built into your public sites is much like having a Q&A site but not allowing people to answer. In this case some of the questions are:

  • Where did you come from?
  • How long did you stick around for?
  • Where did you hang out on your visit?

Now I’m not going to debate which set of analytics is best but I did come across a few quirks when setting Google Analytics (GA) up for wesnolte.com that I suspect are fairly universal.

Build a Site

This of course is quite a big step and I’m going to assume you’re just about done. To get analytics up and running though you’re going to have to do a few extra bits.

Don't hack me pls.

  1. Sign up for a GA account, create a Website Profile and you’ll receive an Analytics Code. My code has been blocked out in orange in the image alongside, your code should appear in it’s place.
  2. Insert the standard Google Analytics Visualforce component into your page.
  3. Enter the same Analytics Code as above on the Force.com Site Detail page – the field is called “Analytics Tracking Code”.

If you go back to your Analytics home page and refresh you’ll see a little warning sign that tells you something is amiss – and it is but it’s difficult to figure out just what that something is.

S.O.S

The problem in this case is that the default robots.txt file for Force.com Sites blocks all bots. This is not a bad idea but it’s not obvious when setting all this up.

Michaelforce and myself seemed to have had these pains at the same time and he posted his findings here. You’ll need to apply step 3 from his post to allow GA to peek at your site.

Now in my particular case I did all of this and GA was still not able to access my site so I threw in the towel and coded the GA JavaScript straight into my page. A few days later however I realised that the robots.txt was probably caching so I ripped out that funky ol’ JavaScript, plugged the Visualforce component back in and BHAM! It worked. Now I know that exactly 5 people visit my site per day, and that 4 of them of from the UK :P

Some Advice

My analytics are working a charm but I’ve realised there’s a snag. Since salesforce.com doesn’t allow you access to their nameservers you have to point your root domain to your Force.com Site using URL forwarding at the domain registrar’s side i.e. I can use a CNAME to point www.wesnolte.com to my Force.com site but wesnolte.com has to bounce to my registrars forwarding server before it finally hits the real site. What this means is that – to GA – the traffic directly to wesnolte.com looks like it’s all coming from one source, that is the forwarding server. The only way that I know to work around this is to get people to only use the http://www.domain.com form of your URL – not ideal I know.

About these ads

Written by Wes

March 11, 2011 at 7:26 pm

3 Responses

Subscribe to comments with RSS.

  1. Great post Wes!! just a quick observation, if I type in http://www.wesnolte.com, I’m not redirected to wesnolte.com, instead I get a page from Virgin Media saying ‘Sorry! we could not find http://www.wesnolte.com‘.

    Anup Jadhav

    March 14, 2011 at 2:23 pm

    • Doh! I must’ve deleted the CNAME record :\ It’s back and should be replicated to the DNS servers in a few hours at most. Thanks for getting my back.

      Wes

      March 14, 2011 at 2:55 pm

      • no probs buddy!! Now i’m redirected to ‘https://na7.salesforce.com/’ Not sure if this is temporary till the dns servers get updated.

        Anup Jadhav

        March 14, 2011 at 4:13 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 2,199 other followers

%d bloggers like this: