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

feat(Surveys): Activate surveys based on actions #1295

Merged
merged 6 commits into from
Jul 10, 2024

Conversation

Phanatic
Copy link
Contributor

@Phanatic Phanatic commented Jul 9, 2024

Broken out of #1292 into its own PR for easier reviewing and merging

This PR allows us to activate surveys if any actions they're configured with are performed in the browser.

Changes

Survey Event Receiver

  1. Instead of maintaining a map of Survey-ID to its actions or events, we maintain a map of Action/Event to the surveys that are activated by it.
  2. We now look for, and register any surveys that are activated by events with the ActionMatcher.
  3. Changed on to be onEvent and added a new onAction event handler.
  4. onAction listens on the actionCaptured event in ActionMatcher described below.

Flowchart for activating surveys based on actions.

flowchart TD
    A[User clicks button] -->|AutoCapture| B(Analyze element)
    B --> |Element matches known selector|C(Set $element_selectors property)
    C -->D[Capture Action]
    B --> |Element does not match known selector|D[Capture Action]
    D --> |Raise eventCaptured with CaptureResult|E[Event Handlers]
    E --> F[Action Matcher]
    F --> |Check Action Step Matches CaptureResult|G[Raise actionCaptured with actionName]
    G --> H[Survey Event Receiver onAction]
    H --> I[Match action name to surveys activated by it]
    I --> |actionName matches a survey's actions|J[Add survey to activatedSurveys]
Loading

Checklist

  • Tests for new code (see advice on the tests we use)
  • Accounted for the impact of any changes across different browsers
  • Accounted for backwards compatibility of any changes (no breaking changes in posthog-js!)

Copy link

vercel bot commented Jul 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
posthog-js 🛑 Canceled (Inspect) Jul 9, 2024 4:39pm

Copy link

github-actions bot commented Jul 9, 2024

Size Change: +24.4 kB (+2.12%)

Total Size: 1.17 MB

Filename Size Change
dist/array.full.js 323 kB +6.09 kB (+1.92%)
dist/array.js 161 kB +6.09 kB (+3.94%)
dist/main.js 161 kB +6.09 kB (+3.92%)
dist/module.js 161 kB +6.09 kB (+3.94%)
ℹ️ View Unchanged
Filename Size
dist/exception-autocapture.js 10.4 kB
dist/recorder-v2.js 110 kB
dist/recorder.js 110 kB
dist/surveys-preview.js 59.6 kB
dist/surveys.js 64.7 kB
dist/tracing-headers.js 8.26 kB
dist/web-vitals.js 5.79 kB

compressed-size-action

@Phanatic Phanatic changed the title feat(Surveys) Activate surveys based on actions feat(Surveys): Activate surveys based on actions Jul 9, 2024
Copy link
Contributor

@jurajmajerik jurajmajerik left a comment

Choose a reason for hiding this comment

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

🚢

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.

2 participants