Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are correct in that you can <a href="http://code.google.com/apis/analytics/docs/tracking/asyncUsageGuide.html#PushingFunctions" rel="nofollow noreferrer">push functions onto the analytics queue</a>. Since functions or tracking events are executed/evaluated in the order that you pushed them on to the array, you should be able to do this:</p> <pre><code>function trackDownload(link) { _gaq.push(['_trackEvent', 'Downloads', 'Click', 'Setup executable']); _gaq.push(function() { document.location = link.href }); return false; } </code></pre> <p>Note that the try/catch isn't necessary since <a href="http://code.google.com/intl/it-IT/apis/analytics/docs/gaJS/gaJSApi_gaq.html#_gaq.push" rel="nofollow noreferrer"><code>push()</code></a> isn't documented to throw anything (and I'd recommend removing it since empty catch blocks can <a href="https://stackoverflow.com/questions/141441/is-a-javascript-try-catch-ignoring-an-expected-occasional-error-bad-practice">mask other problems</a>).</p> <p>You ask:</p> <blockquote> <p>But it's not clear if this works or if it's just equivalent to the previous one. </p> </blockquote> <p>In your first example (push, setTimeout), the event will be lost if Analytics hasn't finished loading when you do the redirect (because at that time, <code>_gaq</code> is just an array). In the version with the <code>push(function...</code>, then the event will be recorded before the redirect regardless of whether Analytics has finished loading at the time the user hits the download button. For this reason, I would recommend using <code>push(function...</code>.</p> <p>Be warned that the <code>push(function...</code> version will wait for analytics to finish loading before the redirect happens (which sounds like what you want anyway), but you may want to add a way to handle the case where analytics doesn't load.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload