Search code examples
phpjavascriptformseventsanalytics

Triggering JS from PHP form process


I have form, let's say it's on index.php. On submit, it goes through process.php, then finishes on thanks.php. I want to trigger an Analytics Event so I can track my form (no I don't want to use a URL Destination). If I put the Event code on thanks.php, I'm concerned that if people refresh the page, it will re-trigger and give me bad results. So, I want it to trigger from process.php somehow. At the end of process.php, I set the header like this:

header('Location: /thanks.php');  

This is the code for triggering the Event:

_gaq.push(['_trackEvent', 'ClaimDomain', 'ConfirmationPage']);

Is there some way of sending the JavaScript call along with the header, so that it only gets processed as we leave process.php, and not when we refresh thanks.php?

Thanks for your help :)


Solution

  • Not really, PHP is server-side, Javascript is client-side.

    From reading about this though, it sounds like it may be a non-issue:

    Unique events are incremented by unique actions

    Any time a user interacts with an object tagged with a particular action name, the initial interaction is logged as one unique event for that action name. Any additional interaction with the same action trigger for that user's session will not contribute to the unique event calculation for that particular action. This is true even if the user leaves that object and begins to interact with another object tagged via the same action name.

    Source: Event Tracker Guide - Actions.

    So GA will know if they happen to land on the page twice and it will not count as 2 unique events.