CleverTap / clevertap-web-sdk

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

Sometimes register event twice in next.js #95

Open nnfans opened 1 year ago

nnfans commented 1 year ago

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

https://user-images.githubusercontent.com/10711718/205206342-19e52541-e2d5-42a6-acd0-91b498710cb0.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 https://github.com/CleverTap/clevertap-web-sdk/blob/76808137f1e710a8811df8ef1421248abd5f3c43/src/util/requestDispatcher.js#L66-L78

abhushanaj commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

any updates on this?

KambleSonam commented 1 year ago

@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.