当前位置: 动力学知识库 > 问答 > 编程问答 >

google analytics - How to prevent duplicates when tracking conversions with Rails

问题描述:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: