- Andrew Kos
- Bill Burlein
- Bryan Williams
- Christian Vozar
- Jeff Brown
- John Kraus
- Joseph Mak
- Josh Durbin
- Mark Daugherty
- Matt Van Bergen
- Melissa Geoffrion
- Michael Kang
- Michael Chan
- Michael Hodgdon
- Mike Motherway
- Molly McDaniel
- Nadia Maciulis
- Pat McLoughlin
- Paul Michelotti
- Puru Hemnani
- Rohit Srinath
- Ryan Lunka
- Tom Kelly
All Blogs
CITYTECH Blogroll:
Google Analytics and AEM: No JavaScript? No Problem.
Wednesday, February 20, 2013
Many organizations use Google Analytics as either their sole web analytics platform or as a supplement to another product like Adobe SiteCatalyst. Google Analytics is a great tool, but its standard use requires that site visitors have JavaScript enabled. If your organization’s growth strategy includes business in developing nations, you are likely finding that a significant portion of Web traffic is via mobile phones that do not support JavaScript. To increase the integrity of your analytics data, you should implement a solution that counts these otherwise uncounted visitors.
Fortunately, most analytics platforms (Google Analytics included) provide a server-side solution to this problem. I’ve taken Google’s server-side JSP solution and adapted it so it works nicely as part of an AEM page component. You can view the code as a Gist, here.
At a high level, this code is doing almost exactly what the Google Analytics asynchronous JavaScript snippet does: making a GET request to a single-pixel GIF image and appending query string parameters with the appropriate information. If you use Chrome Developer Tools or Firebug, you can see this GET request is made, even with the JavaScript solution. The JSP solution should simply mimic your JavaScript solution, but only if JavaScript cannot execute (this is why the <img> tag is inside a <noscript> tag).
You should keep a few things in mind:
- The code I’ve provided is only a starting point
- Google Analytics will not work completely for visitors who don’t allow cookies
- A non-JavaScript solution does not ignore web crawler traffic
- Caching requirements get a little more complicated, because you need the server to process request specific data
- As written, the JSP solution requires developer intervention for updates
You will need to completely evaluate the code I’ve provided and possibly tweak it. I would suggest adding a custom variable to the GIF request that indicates the page was counted from the non-JavaScript solution. This way you can set up a filter in Google Analytics to distinguish this traffic from the traffic counted with the standard JavaScript solution.
If the visitor does not have cookies enabled, it will reduce the accuracy of the data. This is true of any web analytics product that relies on cookies, using JavaScript or not. With a JavaScript solution, you have the option to check for cookies before counting the page visit. You cannot do this server-side. You may want to use a Google Analytics filter to distinguish cookieless traffic, too. All analytics data has a certain margin of error, so consider this part of it.
This solution will not ignore traffic from web crawlers. Typically they are ignored because most crawlers don’t execute JavaScript. Pay attention to your traffic sources if you feel like crawlers may be skewing your data. Consider a Google Analytics filter for this, as well. Again, consider this part of your margin of error.
Make sure your caching strategy doesn’t prevent this image from loading fresh on every page request, or it won’t count every page visit. With this solution, you cannot allow the AEM dispatcher to cache entire pages. You can consider using server-side includes to minimize the load on the CQ server. It’s the unfortunate drawback to relying on your server to process visitor-specific data. If this is not acceptable for performance or other reasons, you probably want to consider an alternative solution that provides web analytics via web server log analysis.
Finally, unless you “componentize” this functionality in some way, it will require developer intervention to make changes. AEM makes it easy for an author to update an analytics snippet via the authoring interface. Without building that authoring interface, the JSP solution will require a developer to make updates. That also means additional coordination is required to ensure the JavaScript and JSP solutions are counting with the same rules.
No analytics solution is perfect, but using this server-side tracking code gives marketers the option to consider mobile traffic from basic mobile devices. In industries that depend on the developing world for growth, this could mean very valuable marketing insight.
Recent Posts
- Descriptive JMX Beans in AEM/CQ
- Invisible requirements within Business requirements
- Building a better Options Predicate
- Javascript, This, and You.
- Extensionless URLs with Adobe Experience Manager
- The Life of a Tester in Adobe CQ World!
- Limitations of the CQ Parsys Model and the Implementation of a Nested Paragraph System
- Google Analytics and AEM: No JavaScript? No Problem.
- Using Apache FOP to generate a PDF document based on a form submission data
- Configuring SAML in AEM 5.6