Created
February 18, 2019 03:59
-
-
Save YuzuruSano/6eafbffa6a6ea4bae471b51caa064508 to your computer and use it in GitHub Desktop.
youtubeAPI埋め込みのイベントから計測タグ発火させるサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script src="https://www.youtube.com/iframe_api""></script> | |
| <!-- html設定サンプル --> | |
| <div class="js-apiLoader" data-ytid="wUn05hdkhjM" data-an="{event}|{eventCategory}|{eventAction}|{eventLabel}"></div> | |
| <div class="js-apiLoader" data-ytid="AhgwJyMPGNU" data-an="{event}|{eventCategory}|{eventAction}|{eventLabel}"></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var onYouTubeIframeAPIReady = function(){ | |
| (function($) { | |
| $(function(){ | |
| $('.js-apiLoader').each(function(){ | |
| var _that = $(this); | |
| var ytid = _that.data('ytid'); | |
| var andata = $(this).data('an'); | |
| var splited_andata = andata.split('|'); | |
| var player = new YT.Player(_that.get(0), { | |
| videoId: ytid, | |
| width : 640, | |
| height: 360, | |
| events: { | |
| 'onStateChange': function(e){ | |
| var status = e.data; | |
| // start, pause | |
| if (status == YT.PlayerState.PAUSED || status == YT.PlayerState.PLAYING) { | |
| console.log(andata); | |
| dataLayer.push({'event':splited_andata[0],'eventCategory': splited_andata[1],'eventAction': splited_andata[2], 'eventLabel': splited_andata[3]}); | |
| } | |
| } | |
| } | |
| }); | |
| }) | |
| }); | |
| })(jQuery); | |
| }; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment