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

chmln returns strange error (react/next.js) #4

Open
adammo94 opened this issue Sep 30, 2022 · 5 comments
Open

chmln returns strange error (react/next.js) #4

adammo94 opened this issue Sep 30, 2022 · 5 comments

Comments

@adammo94
Copy link

So I have this react (next.js actually) implementation:

useEffect(() => {
    if (!window?.chmln && !!user) {
      chmln.init(CHAMELEON_API_KEY, { fastUrl: 'https://fast.chameleon.io/' });
      chmln.identify(user.id, {
        name: `${user.firstName} ${user.lastName}`,
      });
    }

    if (window?.chmln && !user) {
      chmln.clear();
    }
  }, [user]);

however let's say I just open chrome dev tools and when I log in and type in window.chmln or just chmln it returns something like this:
(t){"progeny-definition"!==t&&(e.instanceMethods.init.apply(this,arguments),d.init.apply(this,arguments))}
If I don't use chmln.identify method it (window.chmln inside dev tools' console) works just fine. What am I doing wrong?

@bnorton
Copy link
Member

bnorton commented Sep 30, 2022

@adammo94 are you encountering a specific error with the above code or just that window.chmln (after calling chmln.identify) looks a little "odd"? The (t){"... is expected since the window.chmln plain object is replaced after the full chameleon JS is loaded into the page.

I'd say your implementation looks good to me -- do you need to anything "more" than what you have here?

@adammo94
Copy link
Author

Yes, here https://help.chameleon.io/en/articles/1228858-how-does-chameleon-work-with-single-page-applications it's said:

There might be some cases when you might want to clear the Chameleon installation but there's no page refresh taking place.
A common case, for example, is when there's no hard refresh when users log out of your SPA.

Which is exactly my case. I want to use window.chmln.clear, however since window.chmln changed into this (t){"... thing I cannot access it and it just gives me loads of errors in console when I try .clear method.

@kovcic
Copy link

kovcic commented Nov 14, 2022

Hello, I have the same issue with chmln.clear not being present, but that's expected according to the export:

Screenshot 2022-11-14 at 10 03 47

So question is what is wrong, the documentation (stating .clear should be used with SPA) or the export missing it?

@damir-minkashev
Copy link

@kovcic Right. chmln lib doesn t provide other functions
window.chmln.clear works

@bnorton
Copy link
Member

bnorton commented Mar 23, 2023

@DamirMinkashev @kovcic I see what you're referencing -- if you store and use the reference to "this library", the object you store will not (yet) have the other JavaScript api functions (such as clear, on, etc.). The immediate workaround is to re-reference window.chmln after the call to init.

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