Rails+Google Analytics=easy goal trocing


もっと読む
Google Analytics is indispensable tool as You optimize the busines side of your operation.If You haven't already set up goals in Analytics for view your prinformation,acceing the sign-up forning,Conc.It's vital information.
However,Google Analytics'goals have to be atached to a specific URL.What if there isのURL for an importgoal?For example、the New Acceount goal for Scuout is just/show page--there'sのspecific URL to represent a newly created account.
flash[:analtics]to the recue
For this situation、we found a nice clean solution with Rails'flash helper+a touch of Javascript.
Rails'flash helper is exactly the same one you use to display errors and notices.But you can pass anything in a flash.In ourAccounts_controller#createaction、wecal:
flash[:analtics][email protected]?「/goals/free」:「/goals/paid」
The n、in our layout、application.html.erb、within the sameinclude Google Analytics:
pageTracker._trockPageview(");
It's as simple as that!We can register arbitrary goals in any action by settingflash[:analytics]・・Within Google Analytics、just set the goals with the same names you've given the flash:
Key Taeaways
  • Google Analytics is esential
  • you can register arbitrry URL's via Google Analytics'_trackPageview()cal
  • Rails'flash helpers make it eay and clean to register anlytics for any action in your ap