I'm wondering what do people do regarding preventing Google Analytics from reporting usage statistics from a development/staging site. For example, in my case, I have Google Analytics widget dropped on several page templates. I periodically copy the whole production site down to my development machine, so that I can ensure to be working with most current data. If I'm not mistaken, even though my production site and domain might be www.mysite.com (which has been registered and verified with GA), and my development site might be http://localhost:xxxx or something like that, I believe that GA still receives usage statistics when I open the pages on localhost to test them, correct?
I know I can set up filters in GA (e.g. IP numbers, etc.), but I thought it'd be great to have some sort of a "switch" in sitefinity, a global setting of some sort, that can enable/disable GA throughout the site as needed. There isn't anything like that already built-in, is there?
What do others do regarding GA and non-production sites? Is it a concern at all? I'd love to hear some best practices on this.
GA will just see if it can match the profile ID (UA-xxxxx) in the request with one of its accounts, regardless from which domain (or localhost) it originates. So this will pollute the tracking data if you don't have further filters. I prefer to configure a separate web property in GA, for test/staging, which will have its own profile ID. Then in .NET I will use one ID or the other, depending on where the site is currently running. One advantage is that you can test GA functionality very well.
I don't know if Sitefinity can help with this. I have the preferred domain as a setting in web.config and a function to check whether the site is currently running locally or not (i.e. does the domain contain "localhost" or not).
Thanks for your input, Arno.
I suppose I could set up a different GA profile with its own ID number. But that would require me to open each of those Page Templates and edit each instance of GA Widget in order to change the ID number, correct? It might be better if GA configuration was somehow centrally managed, but with ability to place the GA widget only on pages/templates which are needed to be reported.
I haven't been using the build in GA functionality of Sitefinity yet. My approach is what I use in the site I'm currently converting to Sitefinity. I plan to stick to that approach and just create one custom function that outputs the GA script with the correct ID, depending on the hostname. Then it's just a matter of calling that function from the base template (either in a widget or not) and it will always use the correct ID.
I see. I had a custom approach in our previous Sitefinity site (3.7) as GA functionality wasn't built in. I had a application variable in web.config called "EnableGoogleAnalytics='true/false'" and some custom code in the root master page. The code depended on EnableGoogleAnalytics value in order to determine whether to insert GA code or not. Naturally, on production site, the app variable was set to true while in dev/stage it was false. It was simple, easy, and worked like a charm. :-)
With our recent migration to 5.3, I started removing some past customizations and replacing them with built-in functionality (if there exists any for the desired effect), in a goal of having a cleaner and more "compliant" environment. I hoped that this would be one of those settings.
But perhaps it's not mature enough, yet. :-(