The InfoStride Forum

TECHNOLOGY => Computing and Internet => Topic started by: 6R on Aug 31, 2011, 03:02 PM

Title: Hacking Google Analytics: Ideas, Tips and Tricks
Post by: 6R on Aug 31, 2011, 03:02 PM
(http://cdn.sixrevisions.com/0174-01_google_hacks_ideas_thumbnail.jpg)
Web analytics is a powerful tool made accessible to all of us through awesome free software such as Google Analytics. These tools are designed to satisfy the general needs of every kind of website out there.

That's why website analytics tools, in general, are very good at offering a fundamental overview of traffic data of a site, but not so good when it comes to answering specific questions.

To get specific questions answered, sometimes you have to work around limitations of your current software.

As a proof of concept, I'll present three examples/ideas for gathering more information in conjunction with Google Analytics.

The purpose of this article is to present some starting points for your further exploration.

Example 1: Where Do Users Come From? Google Analytics (and  other web analytics tools (http://sixrevisions.com/usabilityaccessibility/10-promising-free-web-analytics-tools/)) does a great job of telling you the last web page the user clicked on that got him/her to your website. This last web page is often called the referrer or referral path.

Knowing where the user was before visiting your site is helpful because you can use this data to analyze and understand how people are getting to your site.

The problem, though, is that not all visitors become customers/users on their first visit to your website. In most circumstances, the majority of customers visit a website a few times before deciding to buy something or become a regular visitor.

Taking action based only on the last referral path, as reported by tools like Google Analytics, might leave many opportunities on the table and might not give you enough actionable information.

Hacking Google Analytics to give you all the referrers of each visitor proves to be pretty difficult, and the reports you get still won't answer all of your questions.

Here is how you could do it better:

Below is a sample of such a script. Feel free to experiment and fine-tune it.

 function createCookie(name, value, days) { if(days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); var expires = "; expires=" + date.toGMTString(); } else { var expires = ""; } document.cookie = name + "=" + value+expires + ";domain=" + window.location.hostname + "; path=/"; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i = 0; i < ca.length; i++) { var c = ca; while (c.charAt(0) == ' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) { return c.substring(nameEQ.length,c.length); } } return null; } function googleCookieReferrer() { var feed=readCookie("__utmz"); // If the utmcsr is not found, cancel if(feed.indexOf("utmcsr")==-1) { return null; } if(feed != null) { // New version cookie if(feed.indexOf("%7C") != -1) { feed = feed.split("%7C"); feed = feed[0].split("%3D"); } else { // Old version cookie feed = feed.split("|"); feed = feed[0].split("="); } if(feed[1] != "") { return feed[1]; } else { return ""; } } // Read the Google cookie, and extract the utmcsr parameter from utmz var referrer=googleCookieReferrer(); // If the Google cookie was successfully read, and utmcsr found if(referrer != null && referrer != "") { // Read our cookie if it exists if(readCookie("__rfrr")) { // Cookie data var feed = readCookie("__rfrr");   // Temp cookie string var feed_temp = feed;   // This will hold the last referrer in our cookie var check = "";   // Split the data in our cookie feed = feed.split("|");   // If it's the first element, it's a string if(feed[feed.length-1] == null) { check = feed; } else {   // If multiple elements, it's an array, so get last array item check = feed[feed.length-1]; } // If last element != referrer: write cookie and add new referrer if(check != referrer) { createCookie("__rfrr",feed_temp+"|"+referrer,365); } // If no cookie found: create and populate else { createCookie("__rfrr",referrer,365); } } }
Once the script is in place, you'll be able to answer the following questions:

Example 2: How Much Do Customers Spend? The number one question I get from my clients who use Google Analytics ecommerce tracking (http://code.google.com/apis/analytics/docs/tracking/gaTrackingEcommerce.html) is: Why are there more/less money or orders shown by Google Analytics than in reality?

(http://cdn.sixrevisions.com/0174-02_diy_analytics_spending.jpg)

The answer: Google Analytics is not an accounting application, and it will almost never show exact figures of your sales. Charge backs, tracking code issues and ecommerce implementation not covering all payment methods are just a few reasons why the information provided by Google Analytics will not be precise.

Here is how you could do it better:

You've just created a professional dashboard for your business that will give you a clear and reliable view on what's happening.

Example 3: How Successful Is Website Personalization? Personalizing the experience of your website visitors can bring positive results. For example, according to a Fast Company article (http://www.fastcompany.com/1770673/how-yahoo-got-to-a-billion-clicks), Yahoo!'s personalization algorithm was a key contributing factor to a 270% increase in clicks on the site's home page compared to 2009.

Here are just a couple of examples on what you could do to personalize experiences for your visitors:

Each website has many keywords that drive visitors from search engines on pages that aren't immediately relevant for those keywords.

With the next add-on to the previous hack, you can display a nice bottom overlay to your visitors that would contain just the information they are looking for. Now that's good targeting!

 // Add this to extend the code in Example 1 function googleCookieKeyword() { var feed = readCookie("__utmz"); // If the utmcsr is not found, cancel if(feed.indexOf("utmctr") == -1) { return null; } if(feed!=null) { // New version cookie if(feed.indexOf("%7C") != -1) { feed = feed.split("%7C"); feed = feed[3].split("%3D"); } else {   // Old version cookie feed = feed.split("|"); feed = feed[3].split("="); } if(feed[1] != "") { return feed[1]; } else { return ""; } } else { return ""; } } // Read the Google cookie and extract the utmcsr parameter from utmz var referrer = googleCookieKeyword(); if (referrer == "YOUR_DESIRED_KEYWORD") { // Add your code for displaying the content you desire here }
Conclusion Actionable web analytics is not something that should be left to generic tools and data-gathering methods. You'd be happy to know that it's also not something exclusively affordable only to large companies with big budgets.

As long as we can do some basic coding — and as long as we are devoted to meeting the goals of our website — nothing can stop us from hacking our way to great solutions and innovative workarounds.

I hope this article has inspired you to look into how you can gather richer and more refined data from your own analytics software.

About the Author
(http://cdn.sixrevisions.com/authors/claudiu_murariu_small.jpg)
Claudiu Murariu is a web analyst and co-founder of PadiCode (http://padicode.com/), a company building conversion optimization tools. Claudiu can be found on Twitter (as @padicode (http://twitter.com/padicode)) and on his conversion optimization blog (http://padicode.com/blog/).

Six Revisions
Title: Re: Hacking Google Analytics: Ideas, Tips and Tricks
Post by: wealth on Sep 03, 2011, 12:33 PM
What are the steps to implementing google analytics on smf. Thanks
Title: Re: Hacking Google Analytics: Ideas, Tips and Tricks
Post by: MyInfoStride on Sep 03, 2011, 02:53 PM
Quote from: wealth on Sep 03, 2011, 12:33 PM
What are the steps to implementing google analytics on smf. Thanks

There is a mod already that does that. Search SMF for the mod with "Google" as a search term. Download and install, then input your Google Analytics ID (You need to register for it. It is FREE).

Alternatively, you can get your analytic code and put it in Index.template.php file. search for </body> and put the code before it.
Title: Re: Hacking Google Analytics: Ideas, Tips and Tricks
Post by: wealth on Sep 03, 2011, 09:25 PM
I appreciate your response.