k_mada
k_mada

Reputation: 151

JWPlayer 7 - Set Google Analytics after setup

I am using JWPlayer 7 to initialize a video player manually like this:

jwplayer(videoContainer).setup({
    file: '//content.jwplatform.com/videos/'+ assetID +'.mp4',
    image: '//content.jwplatform.com/thumbs/' + assetID + '.jpg',
    title: title,
    category: "video",
    width: "100%",
    primary: 'html5',
    autostart: autoplay,
    ga: {
        label: "title"
    }
});

Where "title" is passed in as a custom title I generate. In the ga block in my setup, I have to pass a custom title so that in Google Analytics, when I view custom events, the title will show up as "John Doe - John Doe Talks About Stuff" instead of what it shows by default, which is a cryptic looking URL to the video.

However, I discovered that when I setup my video player this way, even though we have transcoded our videos with various qualities, if I pass the video URL through the "file" option like I did above, it will only deliver the lower quality video and it won't give the user the option of selecting different qualities in the video player (1080p, 720p, etc.).

When I initialized my player like this:

<script type="text/javascript" src="http://content.jwplatform.com/players/<video id>-<player id>.js"></script>

JWPlayer would take care of all that for me and the user could select a different quality video. The flip side of calling the player like this is that I can't set the Google Analytics the way I want.

So there are actually three questions I have here:

  1. If I initialize my video player via javascript, is there a way to make it so the video player will let the user select the video quality they want?
  2. Is there a way I can set the ga block AND initialize the video player using just the script reference? So far I haven't found anything that lets me do that.
  3. All our videos are hosted by JWPlayer, so they are all transcoded with the different qualities we specified. Each level of quality has a direct link to that video. My priority is to pass that custom title to Google Analytics, so if I must initialize my video player via javascript, is there any way for me to programmatically access those direct links to each transcoded video? I poked around their Platform API, and I didn't see anything that gave me access to a video's direct URLs.

Upvotes: 1

Views: 782

Answers (1)

Eyad Salah
Eyad Salah

Reputation: 1103

You should use sources when setting multiple video files (Multiple bitrates)

<script>
var playerInstance = jwplayer("myElement");
playerInstance.setup({
      image: "/uploads/myPoster.jpg",
      sources: [{
        file: "/uploads/myVideo-360.mp4"
      },{
        file: "/uploads/myVideo-720.mp4"
      }]
    });
</script>

You can also use JWPlayer events and call the analytics ga method on your own

jwplayer().onPlay(function() {ga('send', 'event', 'JW Video Play', 'Video Title')});

Upvotes: 0

Related Questions