'id.init' event callback is not getting called

Hi,

I’m implementing Y8 login system in my game. Following the JS Quickstart documentation, I have added code like this:

<script>
  var authCallback = function (response) {
    if (response) {
      console.log("[Y8] Login complete");
      console.log(response, response.authResponse.details);
    }
  }

  window.idAsyncInit = function () { // SDK downloaded
    ID.init({
      appId: '6xxxxxxxxxxxxxxxxxxxxxxxxx0'
    });

    ID.Event.subscribe('id.init', function () { // SDK initialized
      console.log("[Y8] SDK initialized");
      ID.getLoginStatus(function (data) { // Try Autologin
        console.log("[Y8] Login status: ", data);
        if (data.status == 'not_linked' || data.status == 'uncomplete') {
          ID.login(loginCallback); // Connect/Request permission
        } else {
          // Not logged in
        }
      });

      ID.Protection.isBlacklisted(function (blacklisted) {
        console.log("[Y8] Is site blacklisted: ", blacklisted);
      });

      ID.ads.init('6xxxxxxxxxxxxxxxxxxxxxxxxx0');
    });
  };
</script>
<script src="https://cdn.y8.com/api/sdk.js" async></script>

But the issue is that:

ID.Event.subscribe('id.init', function () {
  // SDK initialized
  console.log("[Y8] SDK initialized");
});

This is never called. There are no logs in the console related to this. It looks like the SDK is not initialized.

Has anyone else faced this issue before? What is the problem here?

I solved this myself guys. It was because I was subscribing to the event after ID.init() was called, where it should have been reverse.

<script>
  var authCallback = function (response) {
    if (response) {
      console.log("[Y8] Login complete");
      console.log(response, response.authResponse.details);
    }
  }

  window.idAsyncInit = function () { // SDK downloaded
    // subscribe first
    ID.Event.subscribe('id.init', function () { // SDK initialized
      console.log("[Y8] SDK initialized");
      ID.getLoginStatus(function (data) { // Try Autologin
        console.log("[Y8] Login status: ", data);
        if (data.status == 'not_linked' || data.status == 'uncomplete') {
          ID.login(loginCallback); // Connect/Request permission
        } else {
          // Not logged in
        }
      });

      ID.Protection.isBlacklisted(function (blacklisted) {
        console.log("[Y8] Is site blacklisted: ", blacklisted);
      });

      ID.ads.init('6xxxxxxxxxxxxxxxxxxxxxxxxx0');
    });

    // call init after subscribing to the event
    ID.init({
      appId: '6xxxxxxxxxxxxxxxxxxxxxxxxx0'
    });
  };
</script>
<script src="https://cdn.y8.com/api/sdk.js" async></script>

Actually this is a problem in the documentation itself since I pasted the same code from the JS Quickstart documentation.

Y8 Games