Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

feat(metrics): emit flow events for newsletter subscription #5160

Merged
merged 1 commit into from Jun 20, 2017

Conversation

philbooth
Copy link
Contributor

Fixes mozilla/fxa-activity-metrics#79, adding new flow events, flow.newsletter.subscribed and flow.newsletter.unsubscribed, for tracking newsletter subscriptions.

I had to stretch the definition of a flow event somewhat, in order to make this work. Until now we've been quite strict about saying that flow events only occur during sign-in and sign-up. However, users can change their newsletter subscription preferences at any time via the settings screen. So in order to produce meaningful metrics, I've introduced the possibility of emitting these flow events outside of the normal flows. Are we okay with that?

In addition to the events emitted from settings, a subscribed event is also emitted after verification if the user checked the newsletter checkbox during sign-up.

Here are some sample log lines showing the new events:

{"event":"flow.newsletter.subscribed","flow_id":"1d73263b05a807a55a16352b195dc46791d29be9f304dc567068764e8ccefd97","flow_time":4113,"hostname":"Phils-MBP","op":"flowEvent","pid":99411,"time":"2017-06-19T12:59:39.778Z","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:55.0) Gecko/20100101 Firefox/55.0","v":1,"context":"fx_desktop_v3","entrypoint":"menupanel","service":"sync"}
{"event":"flow.newsletter.unsubscribed","flow_id":"1d73263b05a807a55a16352b195dc46791d29be9f304dc567068764e8ccefd97","flow_time":7265,"hostname":"Phils-MBP","op":"flowEvent","pid":99411,"time":"2017-06-19T12:59:42.930Z","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:55.0) Gecko/20100101 Firefox/55.0","v":1,"context":"fx_desktop_v3","entrypoint":"menupanel","service":"sync"}

@mozilla/fxa-devs r?

@shane-tomlinson
Copy link

Are we okay with that?

Yeah, we (at least I) are OK with that.

Copy link

@shane-tomlinson shane-tomlinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question, one nit. Tests well, the expected events show up in the logs. With the nit addressed, r+. Thanks @philbooth! Do you need to update the metrics-events doc with this new event?

@@ -31,6 +32,7 @@ define(function (require, exports, module) {
var notifier;
var preferencesUrl = 'https://marketing.preferences.com/user/user-token';
var relier;
let sentryMetrics;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see sentryMetrics actually used anywhere. Is it needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Unless by "it" you mean the local reference to it, in which case no, I could pass in new SentryMetrics() directly to the Metrics constructor directly. I was only trying to follow the convention used everywhere else but I can change it if it makes you happy.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see now. sentryMetrics is needed by the Flow model, which uses it when it logs errors.

@@ -93,12 +94,23 @@ define(function (require, exports, module) {
},

setOptInStatus (newsletterId, isOptedIn) {
var method = isOptedIn ? 'optIn' : 'optOut';
let method, eventPrefix;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a separate line for each variable declaration.

this.logViewEvent(method);

return this.getMarketingEmailPrefs()[method](newsletterId)
.then(() => {
this.logViewEvent(method + '.success');
// Emit an additional flow event for consistency with
// the call to optIn in the account model
this.logFlowEvent(`newsletter.${eventPrefix}subscribed`);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think about how we can consolidate metrics, ubiquitous language should apply to metric event names too! We have multiple places where both View events and Flow events are logged:

screen shot 2017-06-20 at 10 55 53

settings.communication-preferences.optIn.success and flow.newsletter.subscribed mean the same thing yet have two distinct names, this is a recipe for confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason we have two events is because flow.newsletter.subscribed is also emitted during sign-up if the user checked the box. Re-using the other event name there seemed like a bad option because it specifically mentions settings.communication.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, but it hints that our metrics aren't factored correctly. It seems like a lone event should be triggered, and if the event is done as part of a view, the viewName should be a tag of the event.

Originally, I think the viewName was made part of the event name because DataDog struggled with too many tags but didn't care about the number of distinct event names. I am not sure if this reasoning still holds.

@philbooth philbooth force-pushed the phil/newsletter-flow-events branch from c5b7d29 to d6cd53c Compare June 20, 2017 10:31
@philbooth philbooth merged commit d7c576f into master Jun 20, 2017
@philbooth philbooth deleted the phil/newsletter-flow-events branch June 20, 2017 11:04
@rfk rfk added this to the FxA-0: quality milestone Jul 4, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants