Today a client of ours asked if it was possible to have Google analytics stats and graphs displayed right within Couch's admin panel (a client of his wanted this actually).
I gave it a little thought and came up with this solution (I'm quoting my response verbatim)-
As it turned out, our client liked the solution
I have posted it here hoping it might come in handy for someone else too.
I gave it a little thought and came up with this solution (I'm quoting my response verbatim)-
Hi,
That request from your client about displaying Google stats in Couch admin panel got me thinking.
Google provides an API for this purpose but its use is quite involved and will require a fair bit of effort.
I found another way that is much easier -
http://www.seethestats.com/ is a well known service that uses Google API and does the job for you.
It is meant to display Google analytics stats upon one's website but we can easily use it to show the graphs in our admin panel.
It is a free service and seems very safe -
You basically authorize it to fetch the data from Google on your behalf. No worries here as Google makes sure that your password never gets divulged and that you can cancel the service anytime by cancelling the authorization with Google.
This is how I made it work on my system -
Configure seethestats.com:
1. Create an account on http://www.seethestats.com. It will take you to Google analytics where you inform Google that you are authorizing this service to get data.
2. Let seethestats know the name of your site.
3. You will be asked to choose 6 items that you wish to get displayed (e.g. Visits, Pageviews, Unique visitors etc.) as graphs.
Important thing here is that you can chose to make the items private - that is they will not be displayed to anybody else but you.
I made all the six items private.
Once done, it will show you the graphs (in Flash) and will also display the code that you can place on your website to display the graphs there.
the code is basically just IFrames e.g.
- Code: Select all
<iframe src="http://www.seethestats.com/stats/6660/Visits_a789a6666c9_ifr.html" style="width:700px;height:300px;border:none;" scrolling="no" frameborder="0"></iframe>
Copy the codes as we'll use them in the next step.
Configure Couch:
Once we have the IFrame codes, we need to find a way to get it displayed within Couch.
Couch actually has an editable region just does just this - it is type message.
It is used to output arbitrary HTML in admin panel.
This how I proceeded -
1. Create a new template e.g. stats.php. You can make it non-executable because we do not want to access it via browser using its URL..
- Code: Select all
<cms:template title='Google Analytics' executable='0' >
</cms:template>
2. Create an editable region of type message and make it enclose the IFrame code we got from seethestats e.g.
- Code: Select all
<cms:template title='Google Analytics' executable='0' >
<cms:editable name='google_stats' type='message'>
<iframe src="http://www.seethestats.com/stats/6660/Visits_a789a6666c9_ifr.html" style="width:700px;height:300px;border:none;" scrolling="no" frameborder="0"></iframe>
</cms:editable>
</cms:template>
3. Visit the template in your browser for Couch to pick up the changes.
That is it. This template should now show the stats in the right side of the admin panel when you click on this template.
You might want to make this the very first template listed in the left sidebar so that on opening the admin panel, this is the default template that gets shown in the right side. This can be done by setting the order parameter to a negative number. e.g -
- Code: Select all
<cms:template title='Google Analytics' executable='0' order='-1'>
Try it out and let me know how it goes and if the client likes it.
Thanks and regards
Kamran
As it turned out, our client liked the solution
Thanks Kamran, everything works absolutly great.
I have posted it here hoping it might come in handy for someone else too.