Skip to content
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

📝 Add nextJS app example #53

Closed
wants to merge 3 commits into from

Conversation

maurusrv
Copy link

@maurusrv maurusrv commented Feb 15, 2022

This project illustrates how to import the clevertap-web-sdk on a nextJS app.

Since the module is designed for client-side only, for nextJS apps, one can't straightforwardly import the sdk like:

import clevertap from 'clevertap-web-sdk'

due to the library expecting for window object to be defined. See #52

Aside from a workaround, one can asyncly import it when the component mounts or just before an event push:

async function initializeClevertap(): Promise<CleverTap> {
  const clevertap = await import('clevertap-web-sdk')

  // clevertap.default.init(ACCOUNT_ID, TARGET_DOMAIN)
  // clevertap.privacy.push({ optOut: false })
  // clevertap.privacy.push({ useIP: false })
  clevertap.default.setLogLevel(3)

  return clevertap.default
}

This example app does not include the use of react context for simpler implemention or different state / context management.

// clevertap.default.init(ACCOUNT_ID, TARGET_DOMAIN)
// clevertap.privacy.push({ optOut: false })
// clevertap.privacy.push({ useIP: false })
clevertap.default.setLogLevel(3)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to set setLogLevel(3)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess this example might imply that it is needed. I put it there to make the user see it in the devtool when they try it. Anyway, i guess I can comment that out too.

This is to make example app more focused on its purpose: setup
@Deveshb15
Copy link

Did this work for anyone?

@narender2031
Copy link

yes

@Deveshb15
Copy link

yes

Did you call the function inside a useEffect?

useEffect(() => {
initializeClevertap()
}, [])

@KambleSonam
Copy link
Collaborator

@maurusrv Kindly go through the sample Nextjs web app. Let us know if you are facing any issues here.
https://clevertap-next-demo.vercel.app/
Repo Link - https://github.com/KambleSonam/clevertap-next-demo

@maurusrv
Copy link
Author

@maurusrv Kindly go through the sample Nextjs web app. Let us know if you are facing any issues here. https://clevertap-next-demo.vercel.app/ Repo Link - https://github.com/KambleSonam/clevertap-next-demo

@KambleSonam any differences that i miss between the demo repo and this PR? if none, it should be good as i also see the dev logs too on the demo site.

  1. it has been a year or so since i created this PR. i am still new in contributing to open source so i don't know, should i close this now? I realize maintaining setups in this repo might become a hassle and does not really make sense since frameworks like next will always update. And the info in the description above is already good for others to stumble upon.

  2. also, for the same reason that it has been a year, note that the sample is not using the latest next setup. but the clevertap integration still is relevant as this is still how our setup is right now when using the sdk on our nextjs clients. one can also consider just using the clevertap api using fetch instead if they are using custom events and not the system events.

thanks!

@KambleSonam
Copy link
Collaborator

Yes @maurusrv , you can close the PR. Do let us know if you face any issues with clevertap-web-sdk

@maurusrv maurusrv closed this Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants