youtubeyoutube-channels

Javascript - Detect is user is subscribed to youtube channel


I use Youtube subscribe button (https://developers.google.com/youtube/youtube_subscribe_button ).

Is there any way, while user clicks on it, to initiate my javascript function too?


Solution

  • You just need to add a data element with the function that you need to run.

    <script>
    function myEvent(e) 
    { 
        // do something here 
    }
    </script>
    
    <div class="g-ytsubscribe" data-channel="GoogleDevelopers" data-onytevent="myEvent"></div>
    

    https://developers.google.com/youtube/youtube_subscribe_button#Handling_Events_Demo