We're implementing basic conversion tracking in our Rails app to track sign ups, sales, etc. In each instance, the user gets sent to a thank you page after a form submission, which then loads the tracking code for Google Analytics, AdWords, etc.
What we don't want is for the tracking code to be loaded if the user reaches the thank you page by alternate means- e.g. reloading the page, pressing the back button, etc- as it will trigger duplicate conversion events. What is a good technique for preventing this?
You could do it by placing a cookie during the registration action in the controller and then clearing it with an
after_filter in the thank you controller.
This would allow you to only load the tracking code if the cookie was present, then clear out the cookie after loading the tracking code. Now refreshes will still show the thank you page but won't load the tracking code.
Downside is you would miss anyone that doesn't allow cookies, but you might miss them anyway depending on how your tracking code works.
You should use the session's flash for that. Just set up something in the flash when signing up, so the next call (redirection after logging in) will consume the flash and add the tracking code.