-
Notifications
You must be signed in to change notification settings - Fork 6
Custom event tracking #286
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
Open
marksmith
wants to merge
18
commits into
main
Choose a base branch
from
custom-event-tracking
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b47ac87
Fix unit for configUpdatedAt is seconds
marksmith 46ee309
Add POSTGRES_PORT environment variable override
marksmith ad986b4
Add MYSQL_PORT environment variable override
marksmith f78b9d1
Return Boolean from update settings methods
marksmith ae11bac
Add updater to update settings
marksmith 97c6cd4
Normalize instance variable order
marksmith 9d946af
Add realtime settings updates
marksmith bbd59e1
Remove unused stub methods
marksmith dc86e61
Fix tests
marksmith 867c747
Add tests
marksmith a5782a6
Optimize tests
marksmith 022fe2f
Probe realtime endpoint at startup
marksmith d462637
Fix tests
marksmith 94577c8
Fix assert_logged and refute_logged
marksmith efbe9f7
Add tests
marksmith d83199f
Fix call #settings_updated with event
marksmith 94441c2
Add track user events
marksmith 29ebef3
Add test
marksmith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Tracking events | ||
|
|
||
| `Aikido::Zen.track_user_event` lets you record things happening in your app — like failed logins, signups, or password resets. Zen sends these to Aikido so patterns can be detected, like someone failing to log in 50 times in a minute. | ||
|
|
||
| ```ruby | ||
| # app/controllers/application_controller.rb | ||
| class ApplicationController < ActionController::Base | ||
| private | ||
|
|
||
| def authenticate_user! | ||
| # Your authentication logic here | ||
| # ... | ||
|
|
||
| unless current_user | ||
| Aikido::Zen.track_user_event("user.login_failed") | ||
| return | ||
| end | ||
|
|
||
| Aikido::Zen.set_user( | ||
| id: current_user.id, | ||
| name: current_user.name | ||
| ) | ||
|
|
||
| Aikido::Zen.track_user_event("user.login_succeeded") | ||
| end | ||
| end | ||
| ``` | ||
|
|
||
| Zen automatically picks up the IP address, user agent, and current user (if you called [`setUser`](./user.md)) from the request — you don't need to pass those yourself. | ||
|
|
||
| ## More examples | ||
|
|
||
| ```ruby | ||
| Aikido::Zen.track_user_event("user.signed_up") | ||
| Aikido::Zen.track_user_event("user.password_reset_requested") | ||
| Aikido::Zen.track_user_event("plan.invite_sent") | ||
| Aikido::Zen.track_user_event("payment.failed") | ||
| ``` | ||
|
|
||
| ## Naming events | ||
|
|
||
| Use lowercase with dots to group related events: | ||
|
|
||
| - `user.login_failed` | ||
| - `user.login_succeeded` | ||
| - `user.signed_up` | ||
| - `user.password_reset_requested` | ||
| - `payment.failed` | ||
| - `plan.invite_sent` | ||
|
|
||
| ## Things to know | ||
|
|
||
| `Aikido::Zen.track_user_event` only works inside an HTTP request. If you call it in a background job or a script, nothing gets sent and you'll see a warning in the console. | ||
|
|
||
| If you haven't called `Aikido::Zen.set_user` yet, the event still goes through — it just won't have a user ID attached. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.