Code Monkey home page Code Monkey logo

Comments (6)

itsiprikshit avatar itsiprikshit commented on June 21, 2024 1

Hi,
You can refer to https://github.com/Countly/countly-sdk-web/blob/master/samples/react/src/App-WithRouter.js to integrate Countly into your application. Make sure you load Countly in your root component.
Let me know if it was helpful or not.

from countly-sdk-web.

taribudii avatar taribudii commented on June 21, 2024

thankyou,
But I get ReferenceError: Element is not defined when I import import Countly from 'countly-sdk-web'
I've done what you gave, and I still get the same error

from countly-sdk-web.

itsiprikshit avatar itsiprikshit commented on June 21, 2024

I am guessing this could be due to code transpiling in next or maybe some other case related to ssr.
So what you need to do is remove the countly-sdk-web import from your file (remove the module completely from server) and in your componentDidMount, just replace starting few lines of your code with the following and load countly from cdn (like you are already doing). Everything will be done asynchronously in the browser now (even in ssr).

let Countly = window.Countly || {};
    window.Countly = Countly;
    Countly.q = Countly.q || [];

And if still the error persists, then maybe its not because of country-sdk-web since you'd have removed the npm module of the sdk from the server. Could be something else related to your code.

from countly-sdk-web.

ar2rsawseen avatar ar2rsawseen commented on June 21, 2024

Closing this for now, if you still experience this issue, please reopen :)

from countly-sdk-web.

mateuszmolkaofficial avatar mateuszmolkaofficial commented on June 21, 2024

It would be great if this issue could be reopened. @ar2rsawseen The problem with Next.js and Countly is that next.js works on both server and browser. On server Element is not accessible since it's specific to browser. Could you add a check to make sure Element is used in browser only?

if (process.browser) { ... a lot of code }

This one could help ;) Let me know if I can help somehow!

from countly-sdk-web.

jacknewberry avatar jacknewberry commented on June 21, 2024

We are still having this issue where Countly is throws a ReferenceError when it is imported.

I would expect the library to only begin interacting with the DOM (or doing anything) when init is called. That would allow consumers of the library to control when initialisation occurs.

It is confusing to provide a method to trigger initialisation, but also begin initialising the sdk and interacting with the window at import time.

Moving initialisation activities so that they are only triggered when the sdk consumer expects would make the library more flexible, and unblock the client teams who have commented on this ticket.

from countly-sdk-web.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.