R
R
reds2015-11-30 21:07:56
YouTube
reds, 2015-11-30 21:07:56

How to track Youtube subscribe button events?

I need to track clicks on the "Subscribe" button from Google. Here there is a "generator" of the button and the option "Tracking clicks" - https://developers.google.com/youtube/youtube_subs...
I get the following code:

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

<script>
  function onYtEvent(payload) {
    if (payload.eventType == 'subscribe') {
      // Add code to handle subscribe event.
ga('send', 'event', 'button', 'click', 'nav-buttons');
    } else if (payload.eventType == 'unsubscribe') {
      // Add code to handle unsubscribe event.
    }
    if (window.console) { // for debugging only
      window.console.log('YT event: ', payload);
    }
  }
</script>

<div class="g-ytsubscribe" data-channel="GoogleDevelopers" data-layout="default" data-count="default" data-onytevent="onYtEvent"></div>

The event should be sent by the string "ga('send'...". There is a Google Analytics code on the site, events through the link with onclick are triggered, but the button with the code above does not work, tell me what to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Matrozov, 2015-11-30
@Mear

I'm afraid that everything is bad:
https://code.google.com/p/gdata-issues/issues/deta...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question