Automatically Create new User: Help needed please

Greetings,

I’m attempting to configure the script (web plugin) to create a user automatically when the plugin is loaded. The plugin is not loading with the script below. I am using Notifo at: https://app.notifo.io/

I’m following guidance from this link:

Alternatively you can also define the apiKey property. Then an new user will be created automatically. Use the WebManager API Key for that:

My script is:

<script src="https://app.notifo.io/notifo-sdk.js"></script>
<script>
   var notifo = window['notifo'] || (window['notifo'] = []);
   // Initialize the plugin.
   notifo.push(['init', {
     apiKey: 'WebManager API Key (Key omitted)'
   }]);

   // Subscribe to web push.
   notifo.push(['subscribe']);
</script>

<div id="notifo-button"></div>
<script>
    // Show the notifications widget.
    notifo.push(['show-notifications', 'notifo-button', { style: 'notifo' }]);
</script>

<div id="topic-button"></div>
<script>
    // Show the topic widget.
    notifo.push(['show-topic', 'topic-button', 'some/notifications', { style: 'heart' }]);
</script>

Am I using the WebManager API Key correctly, as per the above example?
If not, kindly let me know how to do it.

The goal is to create a new user when the Web Plugin is loaded.
If I use the User API Key (userToken) with the default script everything works as required.

Thank you for your time and assistance,

This looks fine. What happens exactly?

Hi Sebastian,

The Plugin fails to load.

If I use the property: userToken and use a dedicated user API key, then the plugin loads without an issue.

If I attempt to use the property: apiKey and I use the WebManager API Key, then the Plugin fails to load. No popup, nada, just my empty test page.

And the browser console? Later this day I will add a demo page for that to the UI, perhaps I will experience the same error.

Here’s the output of the console:

jquery-migrate.min.js?ver=3.4.1:2 JQMIGRATE: Migrate is installed, version 3.4.1
notifo-sdk.js:2 NOTIFO SDK: init has not been called yet or has failed.
f @ notifo-sdk.js:2
notifo-sdk.js:2 NOTIFO SDK: init has not been called yet or has failed.
f @ notifo-sdk.js:2
notifo-sdk.js:2 NOTIFO SDK: init has not been called yet or has failed.
f @ notifo-sdk.js:2
notify/:1 Uncaught (in promise) SyntaxError: Unexpected token ‘<’, "<!DOCTYPE "… is not valid JSON

Btw: What is your use case? I think the SDK should also store some stuff in local storage to avoid creating new users. What do you think?

It will be used internally to send notifications to a team via our Intranet.
My main reason for needing “new users” is that I don’t want a specific user to “archive/delete” a notification or interact in a manner that will effect another user.

So, I can’t have 1 user, since the actions of that user translates over to everyone else.

Manually creating users is not an option either, in terms of administration etc. The ideal would be for any new user (Session) that a user is created, and the notification topic which is subscribed to is in effect for that specific user session.

So, to sum it up. If I can automatically create new users on the system, I will be able to publish a notification to anyone via the topic and their specific actions on the notification will not inherit to any other users.

Really silly error. Two methods were executed in the wrong order.

Thanks Sebastian for your responses. Is there anything I can do from my end to resolve this?

I have deployed a new version with the fix.

1 Like

Hi Sebastian,

Please see the Console output and my script.
It’s not working unfortunately,

notifo-sdk.js:1 Uncaught SyntaxError: Identifier '$' has already been declared
    at notifo-sdk.js:1:1
notify/:207 Uncaught SyntaxError: Identifier 'k' has already been declared (at notify/:207:28)
jquery-migrate.min.js?ver=3.4.1:2 JQMIGRATE: Migrate is installed, version 3.4.1
<script src="https://app.notifo.io/notifo-sdk.js"></script>
<script>
   var notifo = window['notifo'] || (window['notifo'] = []);
   // Initialize the plugin.
   notifo.push(['init', {
     apiKey: 'WebManager API Key (Key Omitted)'
   }]);

   // Subscribe to web push.
   notifo.push(['subscribe']);
</script>

<div id="notifo-button"></div>
<script>
    // Show the notifications widget.
    notifo.push(['show-notifications', 'notifo-button', { style: 'notifo' }]);
</script>

<div id="topic-button"></div>
<script>
    // Show the topic widget.
    notifo.push(['show-topic', 'topic-button', 'some/notifications', { style: 'heart' }]);
</script>

Thanks for your patience, time and assistance.

I dont’ see this error. I just copied your snippet to an empty html file and it worked for me

Hi, yes it works on an empty HTML file, but doesn’t work on WordPress anymore. I’m using WordPress. The userToken property doesn’t work anymore either, which worked fine yesterday. Nothing was changed Server-side either. I have tested it on 2 different WordPress instances which use different themes, with the same error I posted earlier, the other instance spits out this:

jquery-migrate.min.js?ver=3.4.1:2 JQMIGRATE: Migrate is installed, version 3.4.1
test/:889 Uncaught SyntaxError: Unexpected token ‘<’
test/:896 Uncaught ReferenceError: notifo is not defined
at test/:896:5
test/:901 Uncaught ReferenceError: notifo is not defined
at test/:901:5
test/:1211 Uncaught SyntaxError: Identifier ‘k’ has already been declared (at test/:1211:28)
common.min.js?ver=3.24.3:3 Uncaught TypeError: Cannot read properties of undefined (reading ‘register’)
at ElementorCommonApp.initComponents (common.min.js?ver=3.24.3:3:159327)
at common.min.js?ver=3.24.3:3:160651
at common.min.js?ver=3.24.3:3:160669
at common.min.js?ver=3.24.3:3:160673
app-loader.min.js?ver=3.24.3:2 Uncaught TypeError: Cannot read properties of undefined (reading ‘CommandBase’)
at 78402 (app-loader.min.js?ver=3.24.3:2:51837)
at webpack_require (app-loader.min.js?ver=3.24.3:2:91090)
at 2584 (app-loader.min.js?ver=3.24.3:2:52212)
at webpack_require (app-loader.min.js?ver=3.24.3:2:91090)
at 34261 (app-loader.min.js?ver=3.24.3:2:55279)
at webpack_require (app-loader.min.js?ver=3.24.3:2:91090)
at app-loader.min.js?ver=3.24.3:2:91880
at app-loader.min.js?ver=3.24.3:2:92536
at app-loader.min.js?ver=3.24.3:2:92540
common.min.js?ver=3.24.3:3 Uncaught TypeError: Cannot read properties of undefined (reading ‘getSettings’)
at Debug.sendErrors (common.min.js?ver=3.24.3:3:69343)
at u (underscore.min.js?ver=1.13.4:2:16295)
hotreload.js?ver=70:50 PEER ID is: hero-peer-nulled1234-being-hueman-sender

More of these errors are not related. I think this one is interesting:

test/:889 Uncaught SyntaxError: Unexpected token ‘<’`

Probably a fetch request that accepts JSON and gets html.

The other errors don’t look like they would be coming from notifo.

I have no clue to be honest. I’m more of a operations guy than a developer. The userToken property worked fine earlier, but that’s not working anymore either. It does work on an empty HTML page, but doesn’t work on WordPress as it did before.

It could be anything, do you have a webpage that i can check myself?

Hi,

I think something is wrong with the build. It creates global variables that interfere with other scripts. I had the same problem here: Txxt Fields no longer editable - #5 by SethKodaa

I have deployed a new version that might fix that.

Hi Sebastian. Thank you, I’ll give it another try tomorrow, it was a busy day for me today. I appreciate your time and assistance.

Thank you Sebastian for all your hard work to get this fixed. Everything is working 100%

I sincerely appreciate it,
Have a great weekend

1 Like