CleverTap / clevertap-web-sdk

CleverTap Web SDK
https://clevertap.com/
MIT License
14 stars 18 forks source link

Getting ReferenceError: window is not defined, when clevertap is initialised in _app.tsx file of NextJs #52

Closed akshaysr-buku closed 1 year ago

akshaysr-buku commented 2 years ago

Whenver i use Clevertap in NextJs _app.tsx i am getting the below error

Screenshot 2022-01-04 at 7 02 21 PM

If the package isn't compatible with Next.js, is there any way I cal initialize clevertap in my App?

akshaysr-buku commented 2 years ago

@akashvercetti

akashvercetti commented 2 years ago

Hi @akshaysr-buku , our SDK is a typically a client side only library and does not by its nature support SSR. Having said that, there might be a workaround here: https://github.com/CleverTap/clevertap-web-sdk/issues/39 or you could try npm install --save-dev @types/clevertap-web-sdk since type-definitions have been created at: DefinitelyTyped/DefinitelyTyped#57546.

abhushanaj commented 2 years ago

Hi @akashvercetti we also use the clever tap at our organization which runs a Next.js app.

We use it using the following strategy, without relying on the SDK.

  1. Create an analytics component, which uses the Next.js Script component to inject the script
    
    import Script from 'next/script'

function Analytics(){ return (

Githubissues.
  • Githubissues is a development platform for aggregating issues.