Attempting to set up YouTube subscription button callbacks

Below is a snippet of code that I tried.

    <script src="https://apis.google.com/js/platform.js"></script>
    <script type="text/javascript">
      function onYtEvent(payload) {
        if (payload.eventType == 'subscribe') {
          // Add code to handle subscribe event.
            alert("hello world")
          });
        } else if (payload.eventType == 'unsubscribe') {
          // Add code to handle unsubscribe event.
          alert("asdf");
        }
        if (window.console) { // for debugging only
          window.console.log('YT event: ', payload);
        }
      }
    </script>
<div class="g-ytsubscribe" data-channelid="UCGsSHWM4ZraLZ8k6m4q4g-A" data-layout="default" data-count="hidden" data-onytevent="onYtEvent"></div>

The problem I am facing is that it does not fire any event when the subscribe button is clicked . In the console, I see the following error:

Uncaught ReferenceError: __ytRIL is not defined
+4
source share
1 answer

Here is a Google bug affecting this issue: https://code.google.com/p/gdata-issues/issues/detail?id=8569

Please make a mistake to get their attention.

This even happens on Google’s own website: https://developers.google.com/youtube/youtube_subscribe_button

+2

Source: https://habr.com/ru/post/1652411/


All Articles