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

Add "$is_initial_event" to capture events #1133

Open
benjackwhite opened this issue Apr 11, 2024 · 0 comments
Open

Add "$is_initial_event" to capture events #1133

benjackwhite opened this issue Apr 11, 2024 · 0 comments

Comments

@benjackwhite
Copy link
Collaborator

We have two deprecated plugins that use expensive caching to try and determine if the event is the first one:
https://github.com/posthog/first-event-today
https://github.com/posthog/first-time-event-tracker

I realised, for the user-side of things we could offload the expensive caching to the clients which now becomes relatively cheap.

Todo this we would need to store something like a map of events and timestamps:

eventTimeMaps: {
  "$pageview": Date.now(),
  "custom-event": Date.now()
}

Then everytime we capture event the logic is pseudo:

if (!eventTimeMaps[event.event]) {
  properties["$is_first_event"] = true
  eventTimeMaps[event.event] = Date.now()
} else if (eventTimeMaps[event.event].date < Date.now().date) {
  properties["$is_first_event_today"] = true
  eventTimeMaps[event.event] = Date.now()
}
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

No branches or pull requests

1 participant