Google Analytics - virtual pageview only if registration is successful
Currently when a new user completes the signup process i send them开发者_开发技巧 to the homepage with a param "welcome" equal to 1, which tells the homepage to put a couple of bits on the page. I'm also tracking this extra param in google analytics to keep track of signups.
However, there's a problem with this in that if someone reloads the home page, or goes back to it from another page, then this event is triggered again. I've had a request to put a virtual page view on the submit button for the signup form (like on this page: http://www.google.com/support/forum/p/Google%20Analytics/thread?tid=4e2bca583dc023f1&hl=en) but the problem with this is that it will fire when the user submits the form and it fails validation, which isn't a signup, obviously.
I'm looking for a better approach, basically.
One thing that i have seen suggested is to render out a js snippet calling a virtual page view on the subsequent page, if the signup is successful, dependent on some instance variable for example. This would deal with the refresh situation, as the variable required to shove in the extra js would not be set if the user just refreshes the home page. However, it would be triggered (i think) if the user clicks back to get to that page. The problem with this though is that i do a redirect (rather than render a template) to the home page, so the instance variable wouldn't persist anyway.
Grateful for any advice - max
It's probably not the best way, but what you could do is put the variable into flash. Then you can use this on the view to load the JS or whatever.
So something like this in your controller:
if success?
flash[:notice] = "cool"
redirect_to "somewhere"
end
then something like this in your view:
<%-if flash[:notice] == "cool" %>
// do something funky to track successful registrations
<%- end %>
If the variable won't persist, then maybe the answer is to store a "success" variable in the database that you can expire on the first visit to the homepage so it's used only for the one event you need to track?
精彩评论