Skip to content

Instantly share code, notes, and snippets.

@emmettbutler
Last active August 22, 2018 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save emmettbutler/8a2074b5d37ecb5d6d0b465590ccbd73 to your computer and use it in GitHub Desktop.
Save emmettbutler/8a2074b5d37ecb5d6d0b465590ccbd73 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.video.addStrategy(strategy);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment