-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
node 'node_modules/.bin/jest' '/Users/me/projects/analytics-next/packages/browser/src/browser/__tests__/integration.test.ts' -c '/Users/me/projects/analytics-next/packages/browser/jest.config.js' -t 'reset anonymousId is set if a track event is called during pre-init period' x analytics reset no longer clears anonymousId bug:wq
- Loading branch information
Showing
7 changed files
with
183 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import cookie from 'js-cookie' | ||
|
||
const ajsCookieNames = [ | ||
'ajs_user_id', | ||
'ajs_anonymous_id', | ||
'ajs_group_id', | ||
] as const | ||
const ajsLocalStorageKeys = ['ajs_user_traits', 'ajs_group_properties'] as const | ||
|
||
export const getAjsBrowserStorage = () => { | ||
return getBrowserStorage({ | ||
cookieNames: ajsCookieNames, | ||
localStorageKeys: ajsLocalStorageKeys, | ||
}) | ||
} | ||
|
||
export const clearAjsBrowserStorage = () => { | ||
return clearBrowserStorage({ | ||
cookieNames: ajsCookieNames, | ||
localStorageKeys: ajsLocalStorageKeys, | ||
}) | ||
} | ||
|
||
export function getBrowserStorage< | ||
CookieNames extends string, | ||
LSKeys extends string | ||
>({ | ||
cookieNames, | ||
localStorageKeys, | ||
}: { | ||
cookieNames: readonly CookieNames[] | ||
localStorageKeys: readonly LSKeys[] | ||
}): Record<CookieNames | LSKeys, string | {}> { | ||
const result = {} as ReturnType<typeof getBrowserStorage> | ||
|
||
const cookies = cookie.get() | ||
cookieNames.forEach((name) => { | ||
if (name in cookies) { | ||
result[name] = cookies[name] | ||
} | ||
}) | ||
|
||
localStorageKeys.forEach((key) => { | ||
const value = localStorage.getItem(key) | ||
if (value !== null && typeof value !== 'undefined') { | ||
result[key] = JSON.parse(value) | ||
} | ||
}) | ||
|
||
return result | ||
} | ||
|
||
export function clearBrowserStorage({ | ||
cookieNames, | ||
localStorageKeys, // if no keys are passed, the entire thing is cleared | ||
}: { | ||
cookieNames: string[] | readonly string[] | ||
localStorageKeys?: string[] | readonly string[] | ||
}) { | ||
cookieNames.forEach((name) => { | ||
cookie.remove(name) | ||
}) | ||
if (!localStorageKeys) { | ||
localStorage.clear() | ||
} else { | ||
localStorageKeys.forEach((key) => { | ||
localStorage.removeItem(key) | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.