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

Sometimes register event twice in next.js #95

Open
nnfans opened this issue Dec 2, 2022 · 4 comments
Open

Sometimes register event twice in next.js #95

nnfans opened this issue Dec 2, 2022 · 4 comments
Assignees

Comments

@nnfans
Copy link

nnfans commented Dec 2, 2022

Sometimes the event that triggered appears twice in the clevertap activity tab

Screen.Recording.2022-12-02.at.10.05.57.mov

Printed console:
Screenshot 2022-12-02 at 10 06 44

Registered event
Screenshot 2022-12-02 at 10 08 02

Step to reproduce

  1. clone https://github.com/nnfans/clevertap-repro
  2. yarn
  3. create .env.local
  4. add NEXT_PUBLIC_CT_ID= and fille with clevertap id
  5. yarn dev

Why don't we change the implementation to use fetch api or any http request library instead of appending script tag inside head tag and place the query inside it

// TODO: Try using Function constructor instead of appending script.
var ctCbScripts = document.getElementsByClassName('ct-jp-cb')
while (ctCbScripts[0]) {
ctCbScripts[0].parentNode.removeChild(ctCbScripts[0])
}
const s = document.createElement('script')
s.setAttribute('type', 'text/javascript')
s.setAttribute('src', url)
s.setAttribute('class', 'ct-jp-cb')
s.setAttribute('rel', 'nofollow')
s.async = true
document.getElementsByTagName('head')[0].appendChild(s)
this.logger.debug('req snt -> url: ' + url)

@abhushanaj
Copy link

abhushanaj commented Dec 12, 2022

Hey @nnfans not from the clever tap team, but can it be because of the fact that you are using React 18 and use effect having double runs?

Maybe try to debug mode and check if requests are going twice.

@nnfans
Copy link
Author

nnfans commented Dec 15, 2022

hi @abhu-A-J, you can reproduce it. I already disable the restrict mode that make useEffect fired twice
https://github.com/nnfans/clevertap-repro/blob/main/next.config.js

@nnfans
Copy link
Author

nnfans commented Oct 11, 2023

any updates on this?

@KambleSonam
Copy link
Collaborator

@nnfans This issue is fixed. Kindly update the clevertap-web-sdk package to the latest version v1.6.6.
Let us know if it's resolved for you or issue still persists.

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

No branches or pull requests

4 participants