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

[WIP] User events #302

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft

[WIP] User events #302

wants to merge 15 commits into from

Conversation

polmiro
Copy link
Member

@polmiro polmiro commented Feb 5, 2025

Motivation / Description

Changes introduced

TODO

  • Use autoParseUTMParams helper from @nicfix

nicfix and others added 10 commits January 28, 2025 17:05
## Description

Adds tracking for the SDK initialized event.

## Event Model

An event consists of:
- `id`: uuidv4 generated in the frontend for SDK events as soon as the
event happens. Note it is technically redundant given we also have the
`trace_id` and the `trace_index`.
- `type`: the type of event sent. Includes a prefix for Web Billing
`rcb_`. Follows same pattern as customer center events and paywall
events.
- `trace_id`: uuidv4 generated in the frontend as soon as the SDK is
initialized. All events of the same browser session will be sending this
same `trace_id` until the page is reloaded or exited.
- ~`trace_index`: an incremental 0-based index that describes the
partial order of the events in the same trace.~
- `timestamp`: an epoch in ms of when the event happened in the frontend
using the local clock. Follows same pattern as customer center events
and paywall events.

## Fake Timers

Vitest fake timers proofed a pretty powerful tool for testing the retry
logic of tracking events. It helps give determinism and reduce the
duration of the tests. No more arbitrary waits of X seconds.

## E2E

The e2e test currently fails given the backend does not accept the shape
of the event. It will be solved once the backend PR is merged.

## Retry Logic

The events are sent right away as they happen. If there is an unexpected
response from the browser or an error occurs with the request, the
events will resent in batch with an exponential back-off. Starts with 4s
and has a maximum interval of 60s. The back-off is reset upon successful
submission of the events.

⚠️ Currently the events are sent an infinite amount of times until the
request succeeds.
⚠️ Since events are fired right away if there have not been any errors
there may be multiple requests in-flight that send events to the backend
if none has yet failed.

---------

Co-authored-by: Pol Miro <[email protected]>
## Motivation / Description

Adds tracking for checkout session start event.

I used the label `pr-other` given this is getting merged into
`user-events` branch.

## Changes introduced

- Move tracker specific tests to from `events.test.ts` to
`behavioral-events/events-tracker.test.js`.
- Add a helper to track event `CHECKOUT_SESSION_START`.
- Track event `CHECKOUT_SESSION_START` upon mounting purchases ui.
…idation (#290)

## Motivation / Description

Noticed a bug where upon clicking "continue" with an invalid email it
would not be displaying an error.
## Motivation / Description

Refactored how events are tracked by removing all specific functions
from EventTracker and keeping a simple typed `.track(...)` function. The
event builders are all kept under a single file for now. The API they
offer can also help reduce the boilerplate and noise by accepting more
complex types and pulling the relevant parts into the event.

Also updates the API payload to match the latest spec changes.
…292)

## Motivation / Description

WPL will be tracking some events that need to be in the same trace as
the rest of the `purchases-js` tracked events. There are two main
options:
1. Expose a `_trackEvent` public method marked as `@internal` for
`api-extractor`.
2. Expose the `_trace_id` public value marked as `@internal` for
`api-extractor`.

This pull requests implements the first option which seems like the best
one giving `@internal` tag is meant for such use cases and hides the
`trace_id` implementation detail.

> The @internal modifier is one of the four release tags. It indicates
that an API item is meant only for usage by other NPM packages from the
same maintainer. Third parties should never use "internal" APIs. To
emphasize this, an underscore prefix should be used in the name of a
declaration with an (explicit) @internal tag. API Extractor validates
this naming convention and will report
[ae-internal-missing-underscore](https://api-extractor.com/pages/messages/ae-internal-missing-underscore/)
if the underscore is missing.

See docs for
[here](https://api-extractor.com/pages/tsdoc/tag_internal/).

## Changes introduced

- Expose a public `_trackEvent` marked `@internal` on `Purchases` class.
- Run `npm audit fix`.
… event (#293)

## Motivation / Description

We are interested in tracking when the billing email entry screen is
skipped. But the original trigger for this event is starting a purchase
flow with an already provide email. So instead of tracking a new event,
I am adding the corresponding property to the CheckoutSessionEvent
event.

## Changes introduced

- Add `customerEmailProvided` property to `CheckoutSessionStart` event.
## Motivation / Description

Tracks `CheckoutSessionEnd` event. The start and end of the checkout are
now track upon mounting and closing of the `.purchase(...)`.

## Changes introduced

- Move tracking of `CheckoutSessionStart` to `Purchases`.
- Add tracking of `CheckoutSessionEnd` to `Purchases`.
## Motivation / Description

Adds tracking for the purchase successful events, including impression
and dimiss.

## Changes introduced

- Moved tracking events from `rcb-ui` down whenever possible to:
    -  prevent giant main view to keep growing.
    - fire the events closest to the source.
- Split `EventsTracker.trackEvent(...)` into
`EventsTracker.trackExternalEvent(...)` and
`EventsTracker.trackSDKEvent(...)` to tighten API signatures.
- Add tracking for purchase success impression.
- Add tracking for purchase success dismiss (via main button or cross).
## Motivation / Description

Adds browser context to every event tracked. Based most of it from
Segment's track API.

Notice I decided to:
- Skipped `os` given it's parsed form `user_agent` so rather defer the
calculation to the backend for now.
- Skipped `ip` there is no standard way to fetch it from the browser so
might as well do it on the backend, plus it's going to be more
consistent to the way we gather those anyways in other places.
@RevenueCat-Danger-Bot
Copy link

RevenueCat-Danger-Bot commented Feb 5, 2025

1 Error
🚫 This PR increases the size of the repo by more than 250.00 KB (increased by 323.74 KB).
1 Message
📖 You can bypass the size check failure by adding the label "danger-bypass-size-limit". Please exercise caution.

Generated by 🚫 Danger

polmiro and others added 3 commits February 5, 2025 13:20
## Motivation / Description

Adds tracking events for the payment entry step.

## Changes

- Renamed `TrackedEventName` to `SDKEventName` (vs events tracked via
public `.trackEvent(...)`.
- Fixed email error persisting in the view. Looks like my previous fix
was only partial and this case not covered by the new tests.
- Rearranged tests that are local to the specfic component so they are
not in the global `purchases-ui.tests.js`. Less dependencies and less
giant test file.
- Add tracking for payment entry impression, dimiss, submit and error.

## Additional Comments

Notice I have some tests commented out. I tried to mock the stripe
elements to test the behaviors around them but it proofed to be tricky.
Spent enough time on it that I deemed we can go by without it. There are
much more important behaviors untested anyways compared to event
tracking these that we should prioritize first.

---------

Co-authored-by: Víctor Ferrer García <[email protected]>
## Motivation / Description

Last various couple of updates from the last spec changes.

## Changes introduced

- Event name renames.
- Field name renames.
- Replace `CheckoutPaymentFormErrorEvent` for
`CheckoutPaymentGatewayErrorEvent`.
- Add event `CheckoutFlowErrorEvent`.
- Change property `buttonPressed` for generic `ui_element`.
- Consistent use of `error` and `errorMessage` across events.
- Removed `sdk_version` from the `SDKInitializedEvent` given it's now
sent as context of every request.
## Motivation / Description

This is a safeguard in case at some point we were to run into domain
blocking issues. It happened once in the past and it became problematic
for some users.
## Motivation / Description

Noticed these are redundant given it sends the full URL already. Later
in the data pipeline it can be parsed from it if needed.
## Motivation / Description

This PR implements a couple of changes:
- Flattens event context and properties. Supporting a nested structure
with unknown depth adds complexity that is not require for now. So
taking a step back and keeping it simple. Now properties and context can
only have values of `None`, `number`, `boolean`, `Array<value>`.
- Add new context field `source` to easily identify where the event was
generated (e.g.: `sdk`, `wpl,`khepri`).
- Extended the max interval retry to 5 minutes.
- Add jitter to the retries.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants