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

[Question]: OneSignal.getUserId() doesn't work anymore ? #1141

Open
Trungduc79 opened this issue Nov 19, 2023 · 4 comments
Open

[Question]: OneSignal.getUserId() doesn't work anymore ? #1141

Trungduc79 opened this issue Nov 19, 2023 · 4 comments

Comments

@Trungduc79
Copy link

Trungduc79 commented Nov 19, 2023

How can we help?

I have a script which save UserId into Cookie like this. Its worked perfectly. But now OneSignal.getUserId doesn't work anymore.
I trie some way and got nothing.

Please help me !

Thank a lot !!

<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async=""></script>
  <script>
    function setCookie(cname, cvalue, exdays) {
        const d = new Date();
        d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
        let expires = "expires=" + d.toUTCString();
        document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
    }
    window.OneSignal = window.OneSignal || [];
    OneSignal.push(function() {
        OneSignal.init({
            appId: "<?= ONESIGNAL_KEY ?>",
            allowLocalhostAsSecureOrigin: true
        });
    });
    OneSignal.push(function() {
        OneSignal.getUserId().
        then(response => setCookie('onesignal_player_id', response, 365));
    });
  </script>
@jkasten2
Copy link
Member

@Trungduc79 Thanks for sharing the code but could you provide these details?

  1. Is the OneSignal.getUserId().then() firing with a null response or not at all?
  2. Can you also provide more details such as what browser and operating systems you have tested?
  3. Can you check the browser's network tab to see if there is a failing request to onesignal.com?
  4. Is a user and subscription being created on the OneSignal dashboard after accepting notification permission?

@Trungduc79
Copy link
Author

Trungduc79 commented Nov 22, 2023

@jkasten2 Thank for your respone !,I give you for more detail,

  1. Is the OneSignal.getUserId().then() firing with a null response or not at all? -> This function return a null result.

  2. Can you also provide more details such as what browser and operating systems you have tested? -> I was run by Chrome, MS EGD on Windows system + Chrome mobile. But same result.

  3. Can you check the browser's network tab to see if there is a failing request to onesignal.com? -> Request find, test send a message stil work. Consol no error.

  4. Is a user and subscription being created on the OneSignal dashboard after accepting notification permission? ->
    --- My bad ----
    -> This still created a new user,

@Trungduc79
Copy link
Author

@jkasten2 Thank for your respone !,I give you for more detail,

Is the OneSignal.getUserId().then() firing with a null response or not at all? -> This function return a null result.

Can you also provide more details such as what browser and operating systems you have tested? -> I was run by Chrome, MS EGD on Windows system + Chrome mobile. But same result.

Can you check the browser's network tab to see if there is a failing request to onesignal.com? -> Request find, test send a message stil work. Consol no error.

Is a user and subscription being created on the OneSignal dashboard after accepting notification permission? ->
--- My bad ----
-> This still created a new user,

@legioz
Copy link

legioz commented Feb 19, 2024

Docs are very deprecated and unsupported, I am moving to Firebase

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

3 participants