Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I'm setting up a banner on a website with the caption View our Demo Video. The Banner has the UTM campaign tracking code setup and working.

On our website I've got an embedded iFrame YouTube video that triggers two events: one if it is played, and one if it reaches the end.

What I'm trying to figure out now is if there's a way to create a Funnel Goal that sees if someone came in from the banner, did they proceed to watch the video?

This is a snippet of the code I used to capture the YouTube event

if (event.data == YT.PlayerState.PLAYING) {
      ga('send', 'event', 'YouTube', 'Started', 'Promo from Main Page');
    }
share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

Yesterday while reading and thinking about this is dawned on:

utm_source, utm_campaign, and utm_medium all get passed through as PHP variables. I'm no coder so this is very, very sloppy in execution. I might touch it up when I have the time since it would be hard to add additional campaigns if we were to run more then one banner at a time.

Somewhere towards the top of the page with the video I added:

<!-- checks the utm_source -->    
<?php 

if(isset($_GET['utm_source'])) {
    $utm_source = $_GET['utm_source'];
} else {
    $utm_source = 'zilch';
}

?>

Then I edited the YouTube event handling to add an If/Then Statement which is where it gets even messier.

function onPlayerStateChange(event) {
        if (event.data == YT.PlayerState.PLAYING) {
            if (utm_source == 'zilch') {
                ga('send', 'event', 'YouTube', 'Started', 'Promo from Main Page');
            }
            else if (utm_source == 'EXAMPLE') {
                ga('send', 'event', 'YouTube', 'Started', 'Promo from Main Page via EXAMPLE');
            }
            else {
                ga('send', 'event', 'YouTube', 'Started', 'Promo from Main Page');
            }
        }
        if (event.data == YT.PlayerState.ENDED) {
            if (utm_source == 'zilch') {
                ga('send', 'event', 'YouTube', 'Finished', 'Promo from Main Page');
            }
            else if (utm_source == 'EXAMPLE') {
                ga('send', 'event', 'YouTube', 'Finished', 'Promo from Main Page via EXAMPLE');
            }
            else {
                ga('send', 'event', 'YouTube', 'Finished', 'Promo from Main Page');
            }
    }
  }

It's not the prettiest since this is the first real javascript I've ever worked with but it does function exactly how I need it to.

Ideally within the javascript it should check if utm_source is set to a value and if so append that value to the ga event link. If not then leave the ga event link as it is. If anyone knows how to do that feel free to leave a comment or additional answer.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.