Thanks, edited my question.

I need a reliable way to capture a GA event whenever the GA tracking code fires for a particular page only. Doing so because we want to assign a dollar value to simply viewing a certain page (or type of page), and this can happen multiple times per visit, so a destination based goal isn't feasible

I tried using a window.onload javascript (also tried window.onbeforeunload) to trigger the event, but I can only get about 80% of the pageviews to become events (and only about 12% for our mobile website!). Not accurate enough yet for "prime time"

Thanks :)


In your GA script you can place the event. Although I can't think of a single reason you would want to do this, that's your thing, not mine I suppose.

Just place your event in the same script tag right above the first line (usually var _gaq = _gaq || [];).

Also, PHP has nothing to do with JS as it is server-side, JS is client-side.

  • Thanks I'd be glad to give this solution a try and mark your answer as accepted; would you mind putting that code in context for me, i.e. making this line of code look more complete? This looks kind of sparse to my eyes – Drewdavid Aug 8 '13 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.