views:

17

answers:

1

Each user on my site has a "section" of their own at a part like /user/20

I want each user to be able to specify a Google Analytics code, e.g. UA-12345-6 and have that Google Analytics code placed at the foot of every page. That is fine and I can do that no problem.

How will each user set up their Google Analytics code though? When they are asked to put in the URL of the site, I'd like them to be able to put in the domain name of my site, i.e. www.mydomain.com , not the specific url i.e. www.mydomain.com/user/20

If they put in just the domain, they won't be able to verify that the tracking is working as Analytics will check that domain and not find their code. Is the only way to do this to get them to enter the url as their specific path to their section?

+1  A: 

FIrst, load you analytics 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"));
                </script>

Then track the pageview

<script type="text/javascript">
var tracker = _gat._getTracker("UA-XXXX-X");
tracker._setCookiePath("/your/path/here/");
tracker._trackPageview();
</script>
Horia Dragomir
Sorry, I've maybe not been very clear in my question. It's not about the code I put in the source, but the fact that the user's specific analytics code will not be shown on my homepage (www.mydomain.com)Their Google code will be seen on www.mydomain.com/user/20 instead and on all pages underneath that, e.g. www.mydomain.com/user/20/about etcWhen a user sets up their Google Analytics code inside Analytics, they can find out their code e.g. UA-12345-6 and then come to my application and enter that code.My problem is, unless they enter the specific url, their code won't verify.
Graeme
Sorry for the belated response.Deciding when to display the code is not hard. It also depends on your framework. And the code will be validated on the first visit to the page, you don't need to worry about that.Once the user punches in the code, you can redirect them to said page and that will cause data to be sent to google, thus completing the GA installation.
Horia Dragomir