Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For youtube player tracking #208

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ <h1 id="heading" class="text-center white" data-l10n-id="heading">Celebrate 10 y
</div>
</div>
</div>
<iframe id="topvideo" height="315" src="https://www.youtube-nocookie.com/embed/LtOGa5M8AuU?controls=0&showinfo=0" frameborder="0" allowfullscreen></iframe>

<iframe id="topvideo" height="315" src="https://www.youtube-nocookie.com/embed/LtOGa5M8AuU?enablejsapi=1&controls=0&showinfo=0" frameborder="0" allowfullscreen></iframe>


<div class="small-12 columns share-btn-div text-center">
<div class="share-btn tenyears-video share-button-top"></div>
</div>
Expand All @@ -114,7 +117,7 @@ <h1 id="heading" class="text-center white" data-l10n-id="heading">Celebrate 10 y
<ul class="clearfix text-left">
<li>
<span data-l10n-id="embed-1">Embed the video onto your website or blog</span> <a id="usingThisLink"><span data-l10n-id="embed-2">using this</span> <i class="fa fa-angle-double-right"></i></a>
<textarea id="embedcode" hidden><iframe height="315" src="https://www.youtube-nocookie.com/embed/LtOGa5M8AuU?controls=0&showinfo=0" frameborder="0" allowfullscreen></iframe></textarea>
<textarea id="embedcode" hidden><iframe height="315" src="https://www.youtube-nocookie.com/embed/LtOGa5M8AuU?enablejsapi=1&controls=0&showinfo=0" frameborder="0" allowfullscreen></iframe></textarea>
</li>
<li>
<span data-l10n-id="change-avatar2">Change your profile picture on Facebook, Twitter, Google+, and more to this avatar.</span> <a href="images/avatar.jpg" download target="_blank" id="download-avatar"><span data-l10n-id="download-avatar">Download Avatar</span> <i class="fa fa-angle-double-right"></i></a>
Expand Down Expand Up @@ -163,7 +166,7 @@ <h1 id="heading" class="text-center white" data-l10n-id="heading">Celebrate 10 y
<div class="small-12 message-head columns">
<p class="text-center" id="offline" data-l10n-id="involved-offline">Get involved offline</p>
</div>
<iframe class="columns" height="315" src="https://www.youtube-nocookie.com/embed/j6pwTk4D8WI?controls=0&showinfo=0" frameborder="0" allowfullscreen></iframe>
<iframe id="bottomvideo" class="columns" height="315" src="https://www.youtube-nocookie.com/embed/j6pwTk4D8WI?enablejsapi=1&controls=0&showinfo=0" frameborder="0" allowfullscreen></iframe>
<div class="small-12 columns share-btn-div text-center">
<div class="share-btn offline-video share-button-bottom"></div>
</div>
Expand Down Expand Up @@ -270,7 +273,6 @@ <h1 id="heading" class="text-center white" data-l10n-id="heading">Celebrate 10 y
</div>
</div>
</footer>

<script src="//pontoon.mozilla.org/pontoon.js"></script>
<script src="js/smooth-scroll.min.js"></script>
<script src="js/main.js" defer></script>
Expand Down
52 changes: 46 additions & 6 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
var embedcodeElem = document.getElementById('embedcode');

document.webL10n.ready(function() {
// TODO: change URLs to real videos
var topVideoUrlConfig = {
en: 'https://www.youtube.com/watch?v=LtOGa5M8AuU',
de: 'https://www.youtube.com/watch?v=q8r3HyMnZrQ ',
de: 'https://www.youtube.com/watch?v=q8r3HyMnZrQ',
pt: 'https://www.youtube.com/watch?v=q7d7m_4X8tg'
},
topVideoUrlConfigEmbed = {
en: 'https://www.youtube.com/embed/LtOGa5M8AuU?controls=0&showinfo=0',
de: 'https://www.youtube.com/embed/q8r3HyMnZrQ?controls=0&showinfo=0',
pt: 'https://www.youtube.com/embed/q7d7m_4X8tg?controls=0&showinfo=0'
en: 'https://www.youtube.com/embed/LtOGa5M8AuU?enablejsapi=1&controls=0&showinfo=0',
de: 'https://www.youtube.com/embed/q8r3HyMnZrQ?enablejsapi=1&controls=0&showinfo=0',
pt: 'https://www.youtube.com/embed/q7d7m_4X8tg?enablejsapi=1&controls=0&showinfo=0'
},
topVideoUrl = topVideoUrlConfig.en,
topVideoUrlSrc = topVideoUrlConfigEmbed.en,
Expand Down Expand Up @@ -151,4 +150,45 @@
ga('send', 'event', 'li', 'click', 'tenyears-video-email');
}
});
}());


var s = document.createElement("script");
s.src = "https://www.youtube.com/player_api"; /* Load Player API*/
var before = document.getElementsByTagName("script")[0];
before.parentNode.insertBefore(s, before);

}());



function topVideoGA(event) {
if (event.data == YT.PlayerState.PLAYING) {
ga('send', 'event', 'ChooseIndependentVideo', 'clicked');
}
if (event.data == YT.PlayerState.ENDED) {
ga('send', 'event', 'ChooseIndependentVideo', 'watched');
}
}
function bottomVideoGA(event) {
if (event.data == YT.PlayerState.PLAYING) {
ga('send', 'event', 'FX10Video', 'clicked');
}
if (event.data == YT.PlayerState.ENDED) {
ga('send', 'event', 'FX10Video', 'watched');
}
}

var player1, player2;
function onYouTubeIframeAPIReady(event) {
player1 = new YT.Player('topvideo', {
events: {
'onStateChange': topVideoGA
}
});

player2 = new YT.Player('bottomvideo', {
events: {
'onStateChange': bottomVideoGA
}
});
}