-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTMLElement is not defined when integrating Clevertap in NextJS application #183
Comments
Hi, Is this issue solved for you? |
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 |
For those that can't exactly use 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
|
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
The text was updated successfully, but these errors were encountered: