railslove / rack-tracker

Tracking made easy: Donโ€™t fool around with adding tracking and analytics partials to your app and concentrate on the things that matter.
https://www.railslove.com/open-source
MIT License
647 stars 121 forks source link

Sending rack-tracker events from "backend" code #132

Closed pcraston closed 5 years ago

pcraston commented 5 years ago

Unless I'm missing something very obvious, it's currently only possible to call rack-tracker events in controller actions that render a template as it has to inject the js code.

We have a number of use cases where we need to send a conversion event to Google/Bing/etc in response to something happing to a user's account in "back-end code" (e.g. customers being upgraded to paying clients in rack tasks).

We're currently making this work with some ad-hoc code by setting a boolean flag to the User model, then when the user logs in next we check if that flag is set and then we send the rack-tracker event accordingly.

We want to create a more generic solution for this and I am currently thinking it be best to create a separate project/gem which builds on top of rack-tracker. If you have any thoughts or pointers to something I've missed, that would be much appreciated.

Thanks in advance!

DonSchado commented 5 years ago

Yeah you're absolutely correct, that's the whole idea how the tracker works :) It's basically just a wrapper around the js snippet injection.

The flag approach sounds interesting. Very pragmatic approach.

A more generic solution might be to not use the js snippet injection at all... and maybe use something like a direct API from the providers? But I don't know if they all provide something like that.

Or would it be possible to do something creative in a background node process? maybe a headless browser? :)

bumi commented 5 years ago

I also think using/creating a different gem would be the best approach. Code in rack-tracker pretty much is all about easily collecting data and passing it to the snippets of each service which are injected into the HTML. But that for sure would be very helpful and is requested.

pcraston commented 5 years ago

Ok great feedback, thanks guys! ๐Ÿ™‡ ๐Ÿ˜„

Direct API would be great, but to my knowledge Google Ads/Analytics and Bing don't offer that.

We'll look into a separate gem. Closing this issue for now.