Skip to content

Instantly share code, notes, and snippets.

@joshuarrrr
Forked from emmettbutler/example_strategy.js
Last active August 22, 2018 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuarrrr/65a7bac5ef02307c96ee6ccd16540968 to your computer and use it in GitHub Desktop.
Save joshuarrrr/65a7bac5ef02307c96ee6ccd16540968 to your computer and use it in GitHub Desktop.
An example script demonstrating how to track custom video players with Parse.ly's JavaScript API
var platform = "myVideoPlatform";
var strategy = {
platform: platform,
searchTags: ["DIV"],
verify: function(elem) {
return (' ' + elem.className + ' ').indexOf(" my_video ") !== -1;
},
subscribe: function(elem) {
var playerApi = myVideoJsApi(elem);
playerApi.on("play", function(playedVideoMetadata) {
// this hypothetical player API calls its event handlers with
// the metadata of the video as the only argument. with a different
// player API, you might need to perform some more metadata lookups,
// possibly from disparate data sources.
PARSELY.video.onPlay(playerApi, playedVideoMetadata.id, {
duration: playedVideoMetadata.duration,
image_url: playedVideoMetadata.image_url,
pub_date_tmsp: playedVideoMetadata.pub_date_tmsp,
title: playedVideoMetadata.title,
author: playedVideoMetadata.author,
tags: playedVideoMetadata.tags,
video_platform: platform
});
});
playerApi.on("pause", function(pausedVideoMetadata) {
PARSELY.video.onPause(playerApi, pausedVideoMetadata.id);
});
console.log("Subscribed to custom embed with ID '" + elem.id + "'");
}
};
PARSELY = window.PARSELY || {};
PARSELY.onload = function() {
PARSELY.video.addStrategy(strategy);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment