Last updated: March 21st, 2022
Other relevant documents include our metrics reference and metrics explanation.
How do I...
...create a new activity event?
- Add the event name to
ACTIVITY_EVENTS
inlib/metrics/events.js
. Unless it’s also a flow event (most new events will be one or the other), you should also add it toNOT_FLOW_EVENTS
in the same module. - Emit the new event in code like
request.emitMetricsEvent('foo.bar', { uid })
. - Wherever you emit it, add test cases to cover that the event is correctly logged.
...create a new flow event?
Auth server
- Emit the new event in code like
request.emitMetricsEvent('foo.bar')
. - Wherever you emit it, add test cases to cover that the event is correctly logged.
- Be aware that flow events are only emitted if you have a
metricsContext
. If there’s one in the payload for the current route, you’re all good. If not, the code will try to read one from memcached for you. But a previous call torequest.stashMetricsContext
orrequest.propagateMetricsContext
will need to have been made with the token that your request is authenticated by. Maybe that’s done already, maybe it isn’t, you’ll need to trace the request flow and grep the code.
Content server
- On the front-end, make sure your view has mixed in
FlowEventsMixin
. - view and engage events will be emitted automatically when you add the mixin, for other events you need to call
this.logFlowEvent
from your view. - Add test coverage for the new event to your view unit tests.
...create a new email event?
You don’t need to do this, it’s all set up to work automatically.
...create a new Amplitude event?
Auth server
- Amplitude events are all triggered by activity or flow events, so the first step is to ensure there’s one of those (see above if you need to create a new one).
- If you’re triggering from a specific event, add a new mapping to the
EVENTS
object inlib/metrics/amplitude.js
. If you’re triggering from a set of events, add a mapping toFUZZY_EVENTS
instead. - Add a new test case for the new event to
test/local/metrics/amplitude.js
. Every event should have its own test case in that module.
Content server
- Amplitude events are all triggered by flow or screen events, so the first step is to ensure there’s one of those (see above if you need to create a new flow event).
- If you’re triggering from a specific event, add a new mapping to the
EVENTS
object inserver/lib/amplitude.js
. If you’re triggering from a set of events, add a mapping toFUZZY_EVENTS
instead. - Add a new test case for the new event to
tests/server/amplitude.js
. Every event should have its own test case in that module.