Skip to content

Sometimes register event twice in next.js #95

Description

@nnfans

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions