p105854
p105854

Reputation: 21

YouTube subscribe button - event 'onytevent' not firing

I have got a strange issue with YouTube subscribe button. It seems like a bug on Google's side.

I have a simple code, copied (and slightly modified) from official documentation: jsfiddle.

<script src="https://apis.google.com/js/platform.js"></script>

<div id="yt-console">Console: </div>
<div class="g-ytsubscribe" data-channel="GoogleDevelopers" data-layout="default" data-count="default" data-onytevent="onYtEvent"></div>

<script>
  function onYtEvent(payload) {
    var c = document.getElementById('yt-console');
    c.innerText += ' event';
    if (payload && payload.eventType == 'subscribe') {
      c.innerText += ' subscribe';
    } else if (payload && payload.eventType == 'unsubscribe') {
      c.innerText += ' unsubscribe';
    }
  }
</script>

The button looks different on FF and on Chrome (subscribers counter), but the main problem is that events mechanism is not working. Function onYtEvent is never called. Anyone has any idea for a quick fix to make it working?

Upvotes: 2

Views: 563

Answers (1)

Budos
Budos

Reputation: 31

on the youtube reference it says it has been depricated:

"Note: The Subscribe Button's subscribe and unsubscribe events have been deprecated. Similarly, the data-ytonevent attribute, which could previously be added to the widget element to specify a listener for event notifications, has also been deprecated."

source: https://developers.google.com/youtube/subscribe/reference

Upvotes: 2

Related Questions