Skip to content

Commit

Permalink
Store lmpid in global var for fast access (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
zapo authored Apr 23, 2024
1 parent 2b380ce commit a6a75ad
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/core/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ function toBinary(str: string): string {
return String.fromCharCode(...new Uint8Array(codeUnits.buffer));
}

declare global {
interface Window {
__lmpid?: string;
}
}

class LocalStorage {
private passportKey: string;
private targetingV1Key: string;
Expand Down Expand Up @@ -102,11 +108,13 @@ class LocalStorage {
return;
}

window.localStorage.setItem(this.lmpidKey, provider.ids?.[0]?.id ?? "");
const id = provider.ids?.[0]?.id ?? "";
window.localStorage.setItem(this.lmpidKey, id);
window.__lmpid = id;
}

getLmpid(): string | null {
return window.localStorage.getItem(this.lmpidKey) ?? null;
return window.__lmpid || window.localStorage.getItem(this.lmpidKey) || null;
}

clearPassport() {
Expand Down

0 comments on commit a6a75ad

Please sign in to comment.