executing JS snippet from a controller

Hi All,

I want to execute JS snippet (Google Analytics tracking code) from a controller action.

Is it possible to do this with ExecJS + therubyracer gem? If so, any code example will be highly appreciated.

Is there another way to do such thing?

I know this is not the best way to do this, but currently i'm not rendering any html after this action (it redirects automatically out of site) and I know it is possible to post to GA GIF request.

Thanks, Roy

Hi All,

I want to execute JS snippet (Google Analytics tracking code) from a controller action.

Is it possible to do this with ExecJS + therubyracer gem? If so, any code example will be highly appreciated.

Is there another way to do such thing?

I know this is not the best way to do this, but currently i'm not rendering any html after this action (it redirects automatically out of site) and I know it is possible to post to GA GIF request.

While you could technically execute some javascript code server side, I doubt it will do what you want. Even if you can recreate enough of a browser like environment for the google analytics code to run, it still won't look to google analytics like the request came from that user since you can't get at the cookie google analytics uses for its tracking, it would come from a different ip address etc.

Fred