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,
|
||||
|
||||
Reference in New Issue
Block a user