Skip to content
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

Create a simple event tracking package #472

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

camerow
Copy link
Contributor

@camerow camerow commented Sep 24, 2024

Overview

  • Created two entry points for analytics package: one for web using analytics browser client from segment, and one for native using segment client from react native.
  • Injected into a generic analytics client with configurable options.
  • Planning to make generic functions private and add specific methods for tracking events.
  • Proposing to use uppercase or human-readable event names for better readability.
  • Updating functions to be more generic and customizable via options.

Assumptions

  • Making generic functions private will not impact current usage in apps.
  • Uppercase event names will improve readability and consumption.
  • Adding customizable options for functions will enhance flexibility.

Future steps

I decided to just create the package and not include it anywhere for now. This is just to scope out the work such that we can identify more clearly when we added this to the respective applications, update stakeholders on name changes, etc.

Copy link

codecov bot commented Sep 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 22.38%. Comparing base (936fa26) to head (143a8c5).
Report is 14 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #472   +/-   ##
=======================================
  Coverage   22.38%   22.38%           
=======================================
  Files         132      132           
  Lines        5521     5521           
  Branches      241      241           
=======================================
  Hits         1236     1236           
  Misses       4285     4285           
Components Coverage Δ
bitcoin 53.77% <ø> (ø)
query 12.05% <ø> (ø)
utils 52.45% <ø> (ø)
crypto 69.40% <ø> (ø)
stacks 53.27% <ø> (ø)

@fbwoolf
Copy link
Contributor

fbwoolf commented Sep 24, 2024

Is there an issue to link here?

@camerow
Copy link
Contributor Author

camerow commented Sep 24, 2024

Is there an issue to link here?

There was but I'm struggling to find it. I think I left it in "draft" and possibly lost it.

@camerow
Copy link
Contributor Author

camerow commented Sep 24, 2024

How does the team feel about reusing issues for multiple PRs? I am re-creating this issue, and wondering do we normally create an issue per task or can one issue be represented in multiple PRs?

EDIT: Feel like I answered my own question looking at how these things are linked. One issue per PR seems to be the only real logical choice.

@camerow camerow force-pushed the refactor/segment-analytics branch 2 times, most recently from c92b553 to 87dcb52 Compare September 24, 2024 21:21
@fbwoolf
Copy link
Contributor

fbwoolf commented Sep 24, 2024

How does the team feel about reusing issues for multiple PRs? I am re-creating this issue, and wondering do we normally create an issue per task or can one issue be represented in multiple PRs?

EDIT: Feel like I answered my own question looking at how these things are linked. One issue per PR seems to be the only real logical choice.

You can link multiple issues to one PR if needed ...sometimes a PR will close multiple open issues.

@fbwoolf
Copy link
Contributor

fbwoolf commented Sep 24, 2024

@camerow are you using GH notifications? They can be super helpful. I keep a tab pinned with my notifications always open.

}
// TODO: replace ledger_nativesegwit_add_nonwitnessutxo with this method call.
// TODO: replace ledger_nativesegwit_skip_add_nonwitnessutxo with this method call.
public async trackLedgerNativesegwitAddNonwitnessUtxo(properties: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public async trackLedgerNativesegwitAddNonwitnessUtxo(properties: {
public async trackLedgerNativeSegwitAddNonWitnessUtxo(properties: {


// TODO: replace view_transaction_confirmation with this method call.
public async trackViewTransactionConfirmation(properties: { symbol: string }) {
return this.track('Transaction Confirmation Viewed', properties);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure about the naming pattern change here? @markmhendrickson is this change ok? I know we coordinated the snake_case for naming quite awhile ago.

Choose a reason for hiding this comment

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

I'm cool with updating the naming pattern. Let's just be sure to alias old names to the new ones if we update them, so we can continue reporting consistently.

Copy link
Collaborator

@kyranjamie kyranjamie Sep 25, 2024

Choose a reason for hiding this comment

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

Mentioned on slack, but would push back against this change. What's superior about this naming scheme that warrants the effort of doing the aliasing for 100s of events? Per Mixpanel docs

Generally, adopting snake_case for your event and property names tend to be more robust, especially if you plan to export your Mixpanel data to downstream processes such as data warehouses.

If we ever want to programmatically do anything with this data, we have to start escaping spaces in the ids etc, it's a limiting decision.

I see parallels here with how we're moving to ids for our localisation. sentences !== programatic identifiers.

'defaultProperties' | 'defaultTraits'
>;

export class AnalyticsClient<T extends GenericAnalyticsClient> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the choice here to use a class over a function? We just refactored our api clients away from using classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would like to store a reference to options and creating a class seemed to be the best way. WHat is the disadvantage of a class over a function?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nothing inherently wrong using a class here, and think it's okay for a package like this, but I think Fara's mentioning because we typically favour a more functional approach. Classes often lead to inheritance over composition, mutative methods over pure functions etc. Use of classes in Javascript is a hotly debated topic.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, was just questioning based on Kyran's feedback here. Some suggest to avoid classes in JS if possible, so was just curious about your choice.

Copy link
Contributor

@pete-watters pete-watters left a comment

Choose a reason for hiding this comment

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

Nice work @camerow 👍

This code LGTM so good to merge, especially as the package is not yet consumed.

I like the readability of the uppercase events better but I'm not sure if we need snake_case for some reason

Copy link
Collaborator

@kyranjamie kyranjamie left a comment

Choose a reason for hiding this comment

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

Great start @camerow

packages/analytics/README.md Outdated Show resolved Hide resolved
Comment on lines 13 to 29
const configureAnalyticsClient = ({
writeKey,
defaultProperties,
client,
}: AnalyticsClientConfig) => {
const nativeClient =
client ??
createClient({
writeKey,
});

analyticsClient = new AnalyticsClient(nativeClient, { defaultProperties });

return analyticsClient;
};

export { analyticsClient, configureAnalyticsClient };
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const configureAnalyticsClient = ({
writeKey,
defaultProperties,
client,
}: AnalyticsClientConfig) => {
const nativeClient =
client ??
createClient({
writeKey,
});
analyticsClient = new AnalyticsClient(nativeClient, { defaultProperties });
return analyticsClient;
};
export { analyticsClient, configureAnalyticsClient };
export function configureAnalyticsClient ({
writeKey,
defaultProperties,
client,
}: AnalyticsClientConfig) {
const nativeClient =
client ??
createClient({
writeKey,
});
analyticsClient = new AnalyticsClient(nativeClient, { defaultProperties });
return analyticsClient;
}

Convention used elsewhere is to use function declarations

Comment on lines +24 to +31
export type JsonValue = boolean | number | string | null | JsonList | JsonMap | undefined;

export interface JsonMap {
[key: string]: JsonValue;
[index: number]: JsonValue;
}

export type JsonList = JsonValue[];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like a candidate for utils pkg

Copy link
Collaborator

@edgarkhanzadian edgarkhanzadian left a comment

Choose a reason for hiding this comment

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

Great work!

@@ -0,0 +1 @@
nodejs 20.12.2
Copy link
Collaborator

Choose a reason for hiding this comment

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

As we already have .prototools, i would suggest not using more dot files to keep a version of tools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants