feature(sdk): add ability to set global properties in nextjs
This commit is contained in:
@@ -18,6 +18,7 @@ type OpenPanelComponentProps = Omit<OpenPanelOptions, 'filter'> & {
|
||||
profileId?: string;
|
||||
cdnUrl?: string;
|
||||
filter?: string;
|
||||
globalProperties?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
const stringify = (obj: unknown) => {
|
||||
@@ -37,6 +38,7 @@ const stringify = (obj: unknown) => {
|
||||
export function OpenPanelComponent({
|
||||
profileId,
|
||||
cdnUrl,
|
||||
globalProperties,
|
||||
...options
|
||||
}: OpenPanelComponentProps) {
|
||||
const methods: { name: OpenPanelMethodNames; value: unknown }[] = [
|
||||
@@ -57,6 +59,12 @@ export function OpenPanelComponent({
|
||||
},
|
||||
});
|
||||
}
|
||||
if (globalProperties) {
|
||||
methods.push({
|
||||
name: 'setGlobalProperties',
|
||||
value: globalProperties,
|
||||
});
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<Script src={cdnUrl ?? CDN_URL} async defer />
|
||||
@@ -88,6 +96,18 @@ export function IdentifyComponent(props: IdentifyComponentProps) {
|
||||
);
|
||||
}
|
||||
|
||||
export function SetGlobalPropertiesComponent(props: Record<string, unknown>) {
|
||||
return (
|
||||
<>
|
||||
<Script
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `window.op('setGlobalProperties', ${JSON.stringify(props)});`,
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export function useOpenPanel() {
|
||||
return {
|
||||
track,
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "@openpanel/nextjs",
|
||||
"version": "1.0.3-local",
|
||||
"version": "1.0.5-local",
|
||||
"module": "index.ts",
|
||||
"scripts": {
|
||||
"build": "rm -rf dist && tsup",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@openpanel/web": "1.0.0-local"
|
||||
"@openpanel/web": "1.0.1-local"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"next": "^12.0.0 || ^13.0.0 || ^14.0.0",
|
||||
@@ -20,4 +20,4 @@
|
||||
"tsup": "^7.2.0",
|
||||
"typescript": "^5.2.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@openpanel/web",
|
||||
"version": "1.0.0-local",
|
||||
"version": "1.0.1-local",
|
||||
"module": "index.ts",
|
||||
"scripts": {
|
||||
"build": "rm -rf dist && tsup",
|
||||
@@ -15,4 +15,4 @@
|
||||
"tsup": "^7.2.0",
|
||||
"typescript": "^5.2.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user