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

fix: capture a $pageview event on opting in #1372

Merged
merged 4 commits into from
Aug 29, 2024

Conversation

skoob13
Copy link
Contributor

@skoob13 skoob13 commented Aug 20, 2024

Changes

The initial $pageview is not captured when customers use the opt in/out flow. It creates a discrepancy in event count like this one. The PR changes the behavior to capture the initial $pageview event after a user opts in if the event hasn't yet been sent.

Before

Screenshot 2024-08-20 at 18 01 59

After

Screenshot 2024-08-20 at 18 12 59

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 Aug 20, 2024

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

Name Status Preview Updated (UTC)
posthog-js ✅ Ready (Inspect) Visit Preview Aug 27, 2024 9:26am

Copy link

github-actions bot commented Aug 20, 2024

Size Change: +1.06 kB (+0.09%)

Total Size: 1.17 MB

Filename Size Change
dist/array.full.js 334 kB +265 B (+0.08%)
dist/array.js 155 kB +265 B (+0.17%)
dist/main.js 156 kB +265 B (+0.17%)
dist/module.js 155 kB +265 B (+0.17%)
ℹ️ 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.8 kB
dist/surveys.js 66 kB
dist/tracing-headers.js 8.26 kB
dist/web-vitals.js 5.79 kB

compressed-size-action

Copy link
Collaborator

@benjackwhite benjackwhite left a comment

Choose a reason for hiding this comment

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

Generally looks good. Just a change to make it easier to maintain in the future

Comment on lines 1988 to 1991
if (this.config.capture_pageview && !this._initialPageviewCaptured && document) {
this._initialPageviewCaptured = true
this.capture('$pageview', { title: document.title }, { send_instantly: true })
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we move this block into a private method like captureInitialPageview instead. that way it isn't likely to get forgotten about later in one place or the other

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @benjackwhite! I added a private method.

@benjackwhite
Copy link
Collaborator

Approved - dont forget to bump the label

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump minor Bump minor version when this PR gets merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants