Skip to content

Add and enforce analytics naming convention#9318

Merged
aduth merged 2 commits intomainfrom
aduth-rubocop-analytics-event-name
Oct 10, 2023
Merged

Add and enforce analytics naming convention#9318
aduth merged 2 commits intomainfrom
aduth-rubocop-analytics-event-name

Conversation

@aduth
Copy link
Contributor

@aduth aduth commented Oct 5, 2023

🛠 Summary of changes

Adds a new custom Rubocop linter to enforce a naming convention for analytics, expecting that the first argument to track_event should be a symbol with the same name as the method.

Good:

module AnalyticsEvents
  def my_method
    track_event(:my_method)
  end
end

Bad:

module AnalyticsEvents
  def my_method
    track_event('Some other name')
#               ^^^^^^^^^^^^^^^^^ IdentityIdp/AnalyticsEventNameLinter: Event name must match the method name, expected `:my_method`
  end
end

This was discussed in Engineering Huddle 2023-10-05 (see notes).

The proposal here would not retroactively update existing analytics, but would enforce against all new analytics events moving forward. This is done by adding inline Rubocop disabling for existing events.

📜 Testing Plan

bundle exec rubocop

Copy link
Contributor

@mitchellhenke mitchellhenke left a comment

Choose a reason for hiding this comment

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

👏🏼

Copy link
Contributor

@zachmargolis zachmargolis left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

(Assuming the existing exceptions will be added before merging?)

docs/backend.md Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL the note syntax!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aduth
Copy link
Contributor Author

aduth commented Oct 5, 2023

(Assuming the existing exceptions will be added before merging?)

They're there, but the changes are extensive so GitHub's changes preview collapses the file.

aduth added 2 commits October 5, 2023 12:48
changelog: Internal, Analytics, Add new naming convention for analytics events
@aduth aduth force-pushed the aduth-rubocop-analytics-event-name branch from 70947c9 to 5bfcff1 Compare October 5, 2023 16:50
Copy link
Contributor

@matthinz matthinz left a comment

Choose a reason for hiding this comment

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

Question: Would track_event(__method__) be acceptable or is that too opaque? (For the record, I am 👍 with this PR as-is)

@aduth
Copy link
Contributor Author

aduth commented Oct 6, 2023

Question: Would track_event(__method__) be acceptable or is that too opaque?

Hmm, interesting idea! I don't personally mind it. It does come close to being "clever" programming, but I can't really imagine a scenario where __method__ would obscure discoverability in a way that having the full method name would be better.

I'd probably lean toward keeping this as-is, but I don't feel strongly at all; mostly just care about having it be consistent.

Copy link
Contributor

@soniaconnolly soniaconnolly left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for doing this!

I can imagine that in the future we might want to require the method name as the first part of the analytics name and allow additional words afterward, but we can always add that later if we find we want it.

@aduth
Copy link
Contributor Author

aduth commented Oct 10, 2023

I can imagine that in the future we might want to require the method name as the first part of the analytics name and allow additional words afterward, but we can always add that later if we find we want it.

I'd be curious what this would look like, since my instinct would be that if it should be included in the event name, it could / should also be reflected in the method name?

@aduth
Copy link
Contributor Author

aduth commented Oct 10, 2023

Thanks all for the feedback! As mentioned in Slack, I'll plan to merge this and we can see how it works out. I'll also try to search for open pull requests that might fall victim to this if merged to main without accounting for the new linter.

@aduth aduth merged commit cc3f904 into main Oct 10, 2023
@aduth aduth deleted the aduth-rubocop-analytics-event-name branch October 10, 2023 12:54
@jmhooper jmhooper mentioned this pull request Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants