New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor analytics #443
Refactor analytics #443
Conversation
970e48c
to
2d85f6b
Compare
**Why**: To make it easier to use, and to allow for further simplification down the road. **How**: - Allow the `track_event` method to take a hash as a second argument, which allows adding various properties, rather than having to use the event title as a differentiator. For example, instead of having two event names to track success and failure scenarios, we only have one event name with different attributes. For example: `track_event(:auth, result: 'success')` and `track_event(:auth, result: 'failed')`. - By default, the `track_event` method assumes the user is the current_user or an instance of AnonymousUser. If you need to pass in a specific user, pass in a hash with the key `user_id` and the user's uuid as the value, such as `track_event(:password_reset, user_id: user_from_token.uuid)`. - Remove the `track_anonymous_event` method since it's no longer needed. - Remove the staccato gem and server-side Google Analytics since it doesn't support hash attributes for events. There are other services that can better suit our needs, such as Keen.io, or even storing the data in our own DB.
2d85f6b
to
c735720
Compare
It's not clear to me reading the diff whether anonymous events are tracked with a user_id just like authenticated events. If so, I expect that will be confusing when looking at the logs, seeing a user_id and not being able to reconcile it to the database. |
By default, the |
This was the same behavior as before. This PR did not change the behavior. It just made it possible to have richer and clearer information in the logs, and easier to collect that information. |
The benefit of this attributes hash approach is that we can design our Service Objects that controllers interact with such that they return a hash of attributes about the request, which will allow us to call the For example, let's say a user is trying to reset their password. There are 2 ways this could fail in the first step:
Instead of calling result_hash = ServiceObject.new(params).result
analytics.track_event(:password_reset, result_hash) In the logs, this would show something like:
|
Thanks for the details. The string |
net loss of 70 lines of code! lovely. |
Why: To make it easier to use, and to allow for further
simplification down the road.
How:
track_event
method to take a hash as a second argument,which allows adding various properties, rather than having to use the
event title as a differentiator. For example, instead of having two
event names to track success and failure scenarios, we only have one
event name with different attributes. For example:
track_event(:auth, result: 'success')
andtrack_event(:auth, result: 'failed')
.track_event
method assumes the user is thecurrent_user or an instance of AnonymousUser. If you need to pass in
a specific user, pass in a hash with the key
user_id
and the user'suuid as the value, such as
track_event(:password_reset, user_id: user_from_token.uuid)
.track_anonymous_event
method since it's no longerneeded.
doesn't support hash attributes for events. There are other services
that can better suit our needs, such as Keen.io, or even storing the
data in our own DB.