Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
robbie-c committed Nov 5, 2024
1 parent 1433e18 commit f8f92d5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion playground/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"eslint-config-next": "13.1.6",
"hls.js": "^1.5.15",
"next": "13.5.6",
"posthog-js": "1.166.0",
"posthog-js": "1.178.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "4.9.5"
Expand Down
14 changes: 10 additions & 4 deletions playground/nextjs/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions playground/nextjs/src/posthog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ if (typeof window !== 'undefined') {
person_profiles: PERSON_PROCESSING_MODE === 'never' ? 'identified_only' : PERSON_PROCESSING_MODE,
persistence_name: `${process.env.NEXT_PUBLIC_POSTHOG_KEY}_nextjs`,
...configForConsent(),
__use_cookieless_server_hash: true,
})

// Help with debugging(window as any).posthog = posthog
Expand Down
17 changes: 12 additions & 5 deletions src/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ export class PostHog {
// isUndefined doesn't provide typehint here so wouldn't reduce bundle as we'd need to assign
// eslint-disable-next-line posthog-js/no-direct-undefined-check
if (config.bootstrap?.distinctID !== undefined) {
const uuid = this.config.get_device_id(uuidv7())
const uuid = this._create_device_id()
const deviceID = config.bootstrap?.isIdentifiedID ? uuid : config.bootstrap.distinctID
this.persistence.set_property(USER_STATE, config.bootstrap?.isIdentifiedID ? 'identified' : 'anonymous')
this.register({
Expand Down Expand Up @@ -499,9 +499,7 @@ export class PostHog {
// There is no need to set the distinct id
// or the device id if something was already stored
// in the persistence
const uuid = this.config.__use_cookieless_server_hash
? SENTINEL_COOKIELESS_SERVER_HASH
: this.config.get_device_id(uuidv7())
const uuid = this._create_device_id()

this.register_once(
{
Expand Down Expand Up @@ -1518,7 +1516,9 @@ export class PostHog {
this.sessionPersistence?.clear()
this.persistence?.set_property(USER_STATE, 'anonymous')
this.sessionManager?.resetSessionId()
const uuid = this.config.get_device_id(uuidv7())
const uuid = this.config.__use_cookieless_server_hash
? SENTINEL_COOKIELESS_SERVER_HASH
: this.config.get_device_id(uuidv7())
this.register_once(
{
distinct_id: uuid,
Expand Down Expand Up @@ -2015,6 +2015,13 @@ export class PostHog {
}
}

private _create_device_id(): string {
if (this.config.__use_cookieless_server_hash) {
return SENTINEL_COOKIELESS_SERVER_HASH
}
return this.config.get_device_id(uuidv7())
}

/**
* Opt the user in to data capturing and cookies/localstorage for this PostHog instance
* If the config.opt_out_persistence_by_default is set to false, the SDK persistence will be enabled.
Expand Down

0 comments on commit f8f92d5

Please sign in to comment.