Google Blogoscoped

Forum

Google Docs tracking with Analytics!  (View post)

Jérôme Flipo [PersonRank 10]

Thursday, March 13, 2008
16 years ago15,012 views

Ah ça c'est terrible!
You can now track the number of visitors to your published documents, using the Google Analytics tracking code.

More info in your Google Docs settings...

Philipp Lenssen [PersonRank 10]

16 years ago #

Looks like a neat feature. I'm getting a server error though when trying to save my Google Analytics ID...

<<The bad news is that Google Docs has just encountered an error.

The good news is that you've helped us find a bug, which we are now looking into.>>

Jérôme Flipo [PersonRank 10]

16 years ago #

It didn't bugged at this step, but nothing happened afterward in my Analytics. No new website. Analytics requires to add the tracking code when adding directly docs.google.com as a new website...

TOMHTML [PersonRank 10]

16 years ago #

[put at-character here]Jerome : can you show us some screenshots and give us more explaination?

Luka [PersonRank 10]

16 years ago #

J'adore quand on parle en français sur ce forum!

This would be interesting with the form function, you can now know what is the bounce rate of your form...

Above 5 comments were made in the forum before this was blogged,

TOMHTML [PersonRank 10]

16 years ago #

Currently, you know when was the last edit of your doc. But you don't know when people have seen it, when it is published or not.

Jérôme Flipo [PersonRank 10]

16 years ago #

Here you are!
2 screenshots: one from the Writely settings where I've added my Analytics ID, the other from the tab of a published doc.

http://base.googlehosted.com/base_media?q=hand5514944499892191355&size=1
The two "see your stats" links direct to analytics/home.

But once the settings are saved, nothing changed in my analytics.

I've added docs.google.com as a new website to track, but Analytics doesn't detect the website as a "Google" URL, and requires to add the tracking code, as usual.

Perhaps it works, since Analytics needs 48h to provide stats. But there's still the "check status" alert associated with doc.google.com.

Tony Ruscoe [PersonRank 10]

16 years ago #

I don't think it's going to work as the JavaScript error is:

Error: urchinTracker is not defined
Source File: http://docs.google.com/View?docid=dgdvh3z5_141dq7m8mgj
Line: 228

It seems Google Docs is including the NEW Google Analytics script but using the OLD style code for the tracking code:

<script src="https:// ssl.google-analytics.com/ga.js" type="text/javascript"></script>

<script type="text/javascript">
var page = typeof urchinPage!= 'undefined' ? urchinPage :
window.location.href;
var account = 'UA-18065-1';
if (typeof _gat!= 'undefined') {
var pageTracker = _gat._getTracker(account);
pageTracker._setAllowAnchor(true);
pageTracker._initData();
pageTracker._trackPageview(page);
}
</script>
<script type="text/javascript"><!--
   _uacct = "UA-57585-13";
   _uff = 0;
   urchinTracker('Tracking_Test');
   --></script>

Oops!

Edit: Updated the post with this info too.

TOMHTML [PersonRank 10]

16 years ago #

OK this is available in French too, good point

But I got the same JavaScript error as Tony's.

Ionut Alex. Chitu [PersonRank 10]

16 years ago #

Google Analytics has an excessively complicated interface, especially in the settings section. I think you need to use an existing profile, as you're not allowed to add code to Google Docs' homepage.

Tony Ruscoe [PersonRank 10]

16 years ago #

Agreed. Since Google Analytics allows you to put tracking codes on any website (and not just the one you specify when setting up your profile) you could create a new profile and track all your documents in there.

If you add it to your main profile, you'll end up with loads of filenames in the root of your website (like "Tracking_Test" in my example, according to the code) which will just clutter up the rest of your website stats.

TOMHTML [PersonRank 10]

16 years ago #

[put at-character here]Ionut : I first tried with an existing profile, it fails, I got the same JS error as Tony.

Ionut Alex. Chitu [PersonRank 10]

16 years ago #

The page looks the same because it's generated once, but the script will be corrected at some point. And then you'll need to enter a profile ID.

Philipp Lenssen [PersonRank 10]

16 years ago #

So I went to Google Analytics, added a new website profile for "docs.google.com", and copied the tracker ID. Is that correct? And why doesn't Google explain any of this in their Docs setting page?

PS: Pasting this ID into the Docs settings still doesn't work.

Ionut Alex. Chitu [PersonRank 10]

16 years ago #

No, you can't add a profile for docs.google.com because Analytics will check Google Docs homepage and won't find your code.

Philipp Lenssen [PersonRank 10]

16 years ago #

Isn't it enough if it finds the code on sub-pages of that domain, i.e. all the documents you publish? (Stuff like docs.google.com/Doc?id=ajfjf9foobar.)

Ionut Alex. Chitu [PersonRank 10]

16 years ago #

"The Google Analytics tracking code has not been detected on your website's home page. For Analytics to function, you or your web administrator must add the code to each page of your website."

Philipp Lenssen [PersonRank 10]

16 years ago #

"to each page of your website" is not true, Ionut. I did not include it on each page of this blog, for instance, and it still functions... it will simply omit the traffic on those pages where I didn't put it. I'm not saying that this means you can also omit it from the top domain/ homepage itself, I'm just saying at least you don't need to include on "each page". So I'm still curious if mere sub-pages might be enough... does anyone know for sure? You can't always trust Google's help files :)

Tony Ruscoe [PersonRank 10]

16 years ago #

I think the reason it asks for the code to be installed on the home page is so that it can validate it quickly.

When Analytics first launched, it would just wait to receive data and that would verify it was installed correctly, but that took days. I'm not sure if that method still works though...

Ionut Alex. Chitu [PersonRank 10]

16 years ago #

That's not from a help file. It's the status message after you add a new profile. Since the message is :"tracking code has not been detected on your website's home page", that means Google Analytics checks the homepage.

Philipp Lenssen [PersonRank 10]

16 years ago #

Ionut, again, what makes you think so? It's explanatory help text that may be (and definitely partially is) wrong. How can you be sure they don't simply wait for any feedback ping from that domain, which would be sufficiently fulfilled even if you'd only include the tracker on a sub-page, and then visit that sub-page? Again, I'm not saying that sub-page inclusion *is* sufficient (I don't know either way), I'm merely asking how you can be perfectly sure it *isn't*.

Ionut Alex. Chitu [PersonRank 10]

16 years ago #

The message is "Tracking code not verified".

Philipp Lenssen [PersonRank 10]

16 years ago #

So you were already able to insert your tracking ID into the Google Docs settings? Because as I said, I wasn't able to insert mine as I got an error from Google.

If you did already successfully save your Docs settings page and it still doesn't show up, can you try this: go to your Analytics website profile where you entered docs.google.com. Then click Edit on that profile. Then where you can define the default page for that homepage, provide a value like Doc?id=ajfjf92tmnhd_877cxfoobar, pointing to a published Docs document of yours. Would that work?

Ionut Alex. Chitu [PersonRank 10]

16 years ago #

I don't think you can set a different homepage, but you may be right: the confirmation could be optional.

Philipp Lenssen [PersonRank 10]

16 years ago #

Just to explain, I did indeed set my homepage to Doc?id=ajfjf92tmnhd_877cxfoobar (my document). Well, the only problem being my document doesn't have any tracking code as Google Docs returns an error when I try to save the tracking settings.

Again, I don't want to say I consider it likely any of these hacks would work, I'm just curious if we're able to rule them out for sure. Probably they won't work and Google's help file doesn't lie, who knows :)

Ionut Alex. Chitu [PersonRank 10]

16 years ago #

Yes, I added a profile ID in the settings page and the code was added to my published document:
http://docs.google.com/View?docID=ajg2d6cw8q8n_82gg8djc

Philipp Lenssen [PersonRank 10]

16 years ago #

Hmm, checking the docs.google.com robotst.xt file, this is what I see... does that mean they won't allow the Analytics crawler in?

User-agent: *
Allow: /$
Allow: /support/
Allow: /a/
Disallow: /

Because in a test I just did on another domain, if they crawl the homepage but can't find the code the status will say "Tracking code not detected" but on Google Docs website profile it says "Tracking code not verified".

On the other hand, there is already a tracker code in all pages, perhaps the one by Google.

Philipp Lenssen [PersonRank 10]

16 years ago #

> Yes, I added a profile ID in the settings page
> and the code was added to my
> published document:

So what happens if you include "View?docID=ajg2d6cw8q8n_82gg8djc" as the default homepage in the website profile for "docs.google.com"?

Ionut Alex. Chitu [PersonRank 10]

16 years ago #

Nothing special, probably because the code is not added correctly and urchinTracker doesn't do anything.

Ahab [PersonRank 5]

16 years ago #

Please forgive me if I'm stating the obvious.
I noticed in a Google Docs published document that Google had inserted their New tracking code for their own Account nr UA-18065-1. For this code they did included the relevant JavaScript code the new tracker relies on, i.e. https://ssl.google-analytics.com/ga.js

For the users having their own account nr (like Tony's UA-57585-13) they added the Legacy tracking code, but forgot (?) to include the relevant JavaScript code to have the legacy tracker working, i.e. http://www.google-analytics.com/urchin.js

Interesting is that this notice by Google Analytics seem to have been ignored: "Note: We recommend that you do not include both tracking code snippets together on any given page. Doing so might generate inaccurate report data. You can, however, migrate select pages of your site to the new tracking code while the legacy code remains on others."

I now wonder:
Is it possible at all to to track the same page for two account numbers?
Would altering the New tracking code like this suffice?:

<script src="https ://ssl.google-analytics.com/ga.js" type="text/javascript"></script>
<script type="text/javascript">
var page = typeof urchinPage!= 'undefined' ? urchinPage :
window.location.href;
var account = 'UA-18065-1'; // Google Docs own account nr.
if (typeof _gat!= 'undefined') {
var pageTracker = _gat._getTracker(account);
pageTracker._setAllowAnchor(true);
pageTracker._initData();
pageTracker._trackPageview(page);
}
account = 'UA-57585-13'; // Using Tony Ruscoe's account number
if (typeof _gat!= 'undefined') {
var pageTracker = _gat._getTracker(account);
pageTracker._setAllowAnchor(true);
pageTracker._initData();
pageTracker._trackPageview(page);
}
</script>

[Edit: Changed my Analytics code – Tony]

Tony Ruscoe [PersonRank 10]

16 years ago #

Ahab, thanks for the clearer explanation. That's what I was trying to get across in the update but you did it better than me.

It is possible to track the same page for two accounts. Refer to the example on page 7 of the Tracking Code Migration Guide:

<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">
var firstTracker = _gat._getTracker("UA-12345-1");
firstTracker._initData();
firstTracker._trackPageview();
var secondTracker = _gat._getTracker("UA-67890-1");
secondTracker._initData();
secondTracker._trackPageview();
</script>

http://www.google.com/analytics/GATCmigrationguide.pdf

(Your code would almost work – you'd just need to define the 2nd instance of "pageTracker" as a different variable. I'd avoid using the "account" variable twice too in case it's used in subsequent calls.)

Ahab [PersonRank 5]

16 years ago #

Tony you are right!
I should have noticed that
pageTracker = _gat._getTracker(account);
would create an *object* instance. It's never wise to reuse those... :)

The firstTracker and secondTracker – in the example code – are separate objects, that's much safer...

But now I wonder why the Google Docs programmers didn't use that example... ;)

Ahab [PersonRank 5]

16 years ago #

Tony,
Just another question: what will happen if

var secondTracker = _gat._getTracker("");

I.e. the code for the two account numbers is in place, but the second one is empty (as the user didn't enter it (yet)).

Will this lead to JavaScript or Google Analytics errors? And would it mean much unnescessary overhead (in your opinion)?

Tony Ruscoe [PersonRank 10]

16 years ago #

I would have thought that it would just do nothing. It would try to log the pageview with Analytics but nothing would happen at the other end because the empty "code" doesn't exist. It shouldn't cause an error. As for overheads, it would only mean another HTTP request, so it's no big deal.

Edit: I've just tested this and it didn't cause any errors.

Tony Ruscoe [PersonRank 10]

16 years ago #

Ionut said:
> No, you can't add a profile for docs.google.com because Analytics
> will check Google Docs homepage and won't find your code.
http://blogoscoped.com/forum/126270.html#id126298

I said:
> When Analytics first launched, it would just wait to receive data
> and that would verify it was installed correctly, but that took
> days.
http://blogoscoped.com/forum/126270.html#id126302

I've just tested this and can confirm that it still works this way. You only need to add the code to your home page if you want instant verification.

I just created an account for "www.example.com" and placed the tracking code it gave me on a hidden, buried page inside my website. I visited the page once or twice and now – just 4 hours later – that Google Analytics profile says it's receiving data. So, you should have no problem creating your own "docs.google.com" profile and using that Analytics tracking code in Google Docs.

Of course, you still won't see any data until they fix their tracking code.

Ionut Alex. Chitu [PersonRank 10]

16 years ago #

[ Whoops! I said something stupid.]

Tony Ruscoe [PersonRank 10]

16 years ago #

Where?

Jérôme Flipo [PersonRank 10]

16 years ago #

Ah ça c'est dommage!
Google has removed the faulty feature. Back to work.

PicasaFan [PersonRank 0]

16 years ago #

WHY...can't they make this available for Picasa Online?

Forum home

Advertisement

 
Blog  |  Forum     more >> Archive | Feed | Google's blogs | About
Advertisement

 

This site unofficially covers Google™ and more with some rights reserved. Join our forum!