Open EjDadivas opened 6 months ago
Hi,
Is this issue solved for you? I am getting the same issue.
Just FYI: This issue comes since you are trying to initialize the sdk on the server. Note in next js all the components are by default server side rendered. Initialize the SDK on the client side, it should work correctly. In your case try to add use client
to make the page not server side rendered.
I faced a similar issue while integrating in nuxt.js and I was able to resolve it by disabling SSR from the config.
For those that can't exactly use use client
, you can try dynamic imports.
typeof window !== 'undefined' &&
import('clevertap-web-sdk').then((ct) =>
ct.default.init(process.env.NEXT_PUBLIC_CLEVERTAP)
);
typeof window !== 'undefined' &&
import('clevertap-web-sdk').then((ct) =>
ct.default.event.push(ev, flattenObj(props))
);
Not a fan of how simply importing the package in server side code might break things. But for now, this works for me.
works for me!
in _app.js
const [clevertapModule, setClevertapModule] = useState(null);
...
...
useEffect(() => {
clevertapInit()
}, []);
...
...
const clevertapInit = async () => {
let clevertap = clevertapModule
if (!clevertap) {
clevertap = await initializeClevertap()
}
};
...
...
async function initializeClevertap() {
const clevertapModule = await import('clevertap-web-sdk');
clevertapModule.default.init("************");
clevertapModule.default.privacy.push({ optOut: false });
clevertapModule.default.privacy.push({ useIP: false });
clevertapModule.default.setLogLevel(3);
return clevertapModule.default;
}
``
works for me
import type CleverTap from 'clevertap-web-sdk'
type CleverTapType = typeof CleverTap
let clevertap: CleverTapType
if (typeof window !== 'undefined') {
const cleverTapKey = 'xxxx'
if (cleverTapKey) {
clevertap = require('clevertap-web-sdk')
clevertap.init(cleverTapKey)
}
}
Error I receive:
In my _app.js
Inside my index.js I created a simple app:
I tried this: https://github.com/KambleSonam/clevertap-next-demo but it still doesn't work