Comments (6)
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.
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.
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.
Closing this for now, if you still experience this issue, please reopen :)
from countly-sdk-web.
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.
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)
- Do you offer a notification service for web HOT 2
- Element is Not Defined With React Integrations HOT 1
- Countly installs a non-compliant polyfill for Element.closest HOT 8
- Lighthouse error "Registers an unload listener" from the tracking script HOT 1
- Pass user agent with all requests HOT 1
- [Security Issue] Semi-persistent DOM XSS HOT 2
- How to integrate this sdk with βAnt Design Proβ? HOT 2
- Bug: Countly doesn't correctly remove consent for custom groups. HOT 3
- version inconsistencies HOT 2
- It is not possible to cancel the timed event HOT 5
- Session duration issues HOT 2
- Shipping Countly In a WebWorker Context HOT 11
- Device ID not used for the queued queries when disabling offline mode HOT 1
- Specific consent for remote config HOT 5
- Recommendation: Any plan on modularising the application/splitting into multiple files and also any plan of converting to typescipt. HOT 6
- send json string to countly HOT 2
- Source maps
- Uncaught TypeError: Converting circular structure to JSON HOT 4
- CORS issue with Next.js and countly-sdk-web HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from countly-sdk-web.