TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Google Analytics for developers

95 pointsby yashkeover 12 years ago

13 comments

kevinconroyover 12 years ago
Here are two of my favorite tricks. You can do this just after you set your account ID:<p><pre><code> &#60;!-- Async Tracking Code - http://code.google.com/intl/en-US/apis/analytics/docs/tracking/asyncTracking.html --&#62; &#60;script type="text/javascript"&#62; var _gaq = _gaq || []; _gaq.push(['_setAccount', 'YOUR ANALYTICS ID GOES HERE']); _gaq.push(['_trackPageview']); //******************* // Trick #1: Track page load time in Google Analytics // (note: only works for HTML5 browsers) //******************* _gaq.push(['_trackPageLoadTime']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); //******************* // Trick #2: Add a Javascript error handler so that it creates an event in Google Analytics // whenever there's a CLIENT-SIDE javascript error //******************* window.onerror = function(message, file, line) { var sFormattedMessage = '[' + file + ' (' + line + ')] ' + message; _gaq.push(['_trackEvent', 'Errors', 'Browser', sFormattedMessage, null, true]); } &#60;/script&#62; </code></pre> Update: Included complete GA code to address any confusion on order and values available in stack.
评论 #4876347 未加载
评论 #4876725 未加载
评论 #4877777 未加载
评论 #4876665 未加载
评论 #4876273 未加载
评论 #4876277 未加载
dbarlettover 12 years ago
I'm a big fan of the GAS (Google Analytics on Steroids) wrapper [1]. One of the coolest features is firing GA events from embedded YouTube videos [2] to track viewer retention [3].<p>[1] <a href="https://github.com/cardinalpath/gas" rel="nofollow">https://github.com/cardinalpath/gas</a><p>[2] <a href="https://gist.github.com/2715896" rel="nofollow">https://gist.github.com/2715896</a><p>[3] <a href="http://i.imgur.com/QILnG.png" rel="nofollow">http://i.imgur.com/QILnG.png</a>
dangrossmanover 12 years ago
I was expecting something different with the "for developers" title. Perhaps replicating some of the features of MixPanel or KissMetrics, which can track all kinds of interesting things for developers -- which features users of your app use most, in which order they use those features, whether this week's signups are more engaged than last week's signups, etc.
评论 #4876126 未加载
评论 #4876082 未加载
stephthover 12 years ago
Is anyone using GA to track mobile apps? The mobile SDKs shows a lot of potential until you start wondering about <i>offline</i> usage, GA being a website tracker first. I couldn't find any final answers but from what I can see it might be a sore point: the SDK docs dodge the topic [1] and I see complaints, ie events can be batched for later but get the timestamps of when they were uploaded, instead of when they happened [2,3,4].<p>[1] <a href="https://www.google.com/search?q=site:https://developers.google.com/analytics/devguides/collection/ios/v2/%20offline" rel="nofollow">https://www.google.com/search?q=site:https://developers.goog...</a><p>[2] <a href="http://stackoverflow.com/questions/6618719/how-does-google-analytics-for-android-handle-offline-app-usage" rel="nofollow">http://stackoverflow.com/questions/6618719/how-does-google-a...</a><p>[3] <a href="http://stackoverflow.com/questions/4484748/what-happens-with-iphone-google-analytics-calls-when-theres-no-internet-connect" rel="nofollow">http://stackoverflow.com/questions/4484748/what-happens-with...</a><p>[4] <a href="http://productforums.google.com/forum/#!msg/analytics/132Eet7kVFE/rM_kp4j8uIEJ" rel="nofollow">http://productforums.google.com/forum/#!msg/analytics/132Eet...</a>
评论 #4876760 未加载
bluetideproover 12 years ago
&#62; <i>"You probably use most of basic features of Google Analytics - you know how to get information how many visits was made each day, you know your users browser segmentation etc. But how can you measure effects of your blog post?"</i><p>That hits the nail on the head. Great article, although I wish you went into it a bit more in depth on how to do those actions, how to do other actions, and then maybe talk more about the benefits.<p>I love browsing Google Analytics but I will be the first to tell you that I don't really understand much from it, other than than the obvious things. I really wish I could figure out how to integrate it better with my web sites, like you quickly demoed. Again, I really suggest doing this same article with a bit more information. It would really help out those who are your target audience for this article. Thanks! :)
评论 #4876251 未加载
wiremineover 12 years ago
You can also do this on the server side. Here is a Python implementation: <a href="https://github.com/kra3/py-ga-mob" rel="nofollow">https://github.com/kra3/py-ga-mob</a>
评论 #4877158 未加载
jgalt212over 12 years ago
The article is interesting, but gives some bad instructions on how to track outbound links and also probably how to track form submissions. Because of the asynchronous nature of communications back/forth from Google Analytics if you load a new page before an event is properly tracked, you won't be able to see it on the GA Dashboard. Bad intel is worse than no intel at all.<p>Here's what Google itself has to say on the matter: <a href="http://support.Google.com/analytics/bin/answer.py?hl=en&#38;answer=1136920" rel="nofollow">http://support.Google.com/analytics/bin/answer.py?hl=en&#38;...</a><p>Here's how to correct one code example from the blog post:<p><pre><code> //this function is OK, but probably an unnecessary abstraction of a one-liner function trackEvent(category, action, label) { window._gaq.push(['_trackEvent', category, action, label]) } //this event handler will not track some non-negligible percentage of events $("article a").click(function(e) { var element = $(this) var label = element.attr("href") trackEvent("Outbound link", "Click", label) }); //corrected outbound link event handler which gives GA 100 ms to register //the event. higher than 100 risks UX degradation, lower increases the % //of untracked events. 100 ms is happy medium $("article a").click(function(e) { e.preventDefault(); //stay on the page for now var element = $(this) var label = element.attr("href") trackEvent("Outbound link", "Click", label) //leave the page after a short delay window.setTimeout("window.location.href='" + label + "'", 100); });</code></pre>
评论 #4939736 未加载
iamchrisleover 12 years ago
If you want to track if people are reading your blog, you can use the onscroll javascript event that fires events into Google Analytics. (eg: <a href="http://cutroni.com/blog/2012/02/21/advanced-content-tracking-with-google-analytics-part-1/" rel="nofollow">http://cutroni.com/blog/2012/02/21/advanced-content-tracking...</a>)<p>By looking at time to scroll, time to the end of the blog post, and comparing that to the number of unique page views per visit, you can tell if your content is engaging.
xyzzybover 12 years ago
Those are some good basics.<p>Tracking user actions can be very useful: I use it on movieterminals.com to see everything that gets typed into each console. The theory being that (one day?) I'll use that to enhance the scripts to work how people expect.<p>Tracking an event per page 404 or 500 can also be very helpful. If you aren't already using something more robust to track errors you could even setup alerts to watch for those events and contact you.<p>Goals are good, although funnels are even better.<p>Finally: if you can afford it I've found that Clicky offers many great advantages over google analytics. More helpful default reports, a better realtime view, etc.
campnicover 12 years ago
At the risk of going off topic, a question about sampling and sampling rates. If I set sampling to 1%, will the visitor totals in the Google Analytics dashboards reflect 1% of my true values or do they compensate/extrapolate out to 100% based on the sampling rate?
评论 #4876991 未加载
dudusover 12 years ago
If you want to extract more data from your site to Google Analytics I recommend GAS (Google Analytics on Steroids).<p><a href="https://github.com/CardinalPath/gas" rel="nofollow">https://github.com/CardinalPath/gas</a><p>It adds these events and even more to your site.<p>(I'm the main developer by the way.)
评论 #4880667 未加载
euroclydonover 12 years ago
How can you see individual user sessions using Google Analytics? In other words, how can I see, for an individual visitor, their landing page, sequence of subsequent page views, and finally their exit page?
评论 #4876652 未加载
instakillover 12 years ago
Perhaps I'm confused but what benefit do you get from using event tracking for an outbound click, and lastly what does ET have to do with real time?<p>Thanks
评论 #4876445 未加载
评论 #4876470 未加载