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: Allow changing persistence #1025

Merged
merged 12 commits into from
Feb 20, 2024
Merged

feat: Allow changing persistence #1025

merged 12 commits into from
Feb 20, 2024

Conversation

benjackwhite
Copy link
Collaborator

@benjackwhite benjackwhite commented Feb 14, 2024

Changes

Fixes #1024

  • Also adds tailwind to the next playground

Allows doing something like this:

// Cookieless tracking with swap to cookie-full tracking when enabled
let cookieOptIn = () => localStorage.getItem("cookie-opt-in") === "true"

posthog.init(KEY, { persistence: cookieOptIn() ? "localStorage+cookie" : "memory" }

function optInToCookies() {
    localStorage.setItem("cookie-opt-in", "true")
    posthog.update_config({ persistence: "localStorage+cookie" })
}

Follow up

  • Update docs and notify team to update tutorials (to answer these questions 1 2

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

github-actions bot commented Feb 14, 2024

Size Change: +18.5 kB (+2%)

Total Size: 863 kB

Filename Size Change
dist/array.full.js 183 kB +468 B (0%)
dist/array.js 125 kB +466 B (0%)
dist/es.js 125 kB +466 B (0%)
dist/module.js 125 kB +466 B (0%)
dist/recorder-v2.js 106 kB +1.17 kB (+1%)
dist/surveys.js 64.3 kB +15.5 kB (+32%) 🚨
ℹ️ View Unchanged
Filename Size
dist/exception-autocapture.js 12 kB
dist/recorder.js 58.6 kB
dist/surveys.esm.js 64.2 kB

compressed-size-action

@benjackwhite benjackwhite added bump patch Bump patch version when this PR gets merged bump minor Bump minor version when this PR gets merged and removed bump patch Bump patch version when this PR gets merged labels Feb 15, 2024
Copy link
Member

@pauldambra pauldambra left a comment

Choose a reason for hiding this comment

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

i trust you ran it locally and since the new test passes this looks good to me

package.json Show resolved Hide resolved
playground/nextjs/src/CookieBanner.tsx Outdated Show resolved Hide resolved
src/__tests__/posthog-persistence.test.ts Show resolved Hide resolved
src/posthog-persistence.ts Show resolved Hide resolved
src/posthog-persistence.ts Show resolved Hide resolved
Copy link
Collaborator

@mariusandra mariusandra left a comment

Choose a reason for hiding this comment

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

Had a look through the code, but didn't run. What I saw looks good, and seconding Paul: seems like the test passes, so I trust it works.

@benjackwhite benjackwhite merged commit c820f2c into main Feb 20, 2024
13 checks passed
@benjackwhite benjackwhite deleted the feat/opt-in-cookies branch February 20, 2024 15:20
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.

Allow the SDK to change storage mechanism in-flight
3 participants