I need to track clicks on the "Subscribe" button from Google.
Here there is a "generator" of the button and the option "Track clicks."
I get this 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 send the string "ga('send'..." . The Google Analytics code on the site has events through the link with onclick work, and the button with the code above - no way.
Tell me what to do?