Skip to content

Instantly share code, notes, and snippets.

@prabapro
Last active September 19, 2022 06:31
Show Gist options
  • Save prabapro/f3f3edbef4b993221cc05d794f2b7fcd to your computer and use it in GitHub Desktop.
Save prabapro/f3f3edbef4b993221cc05d794f2b7fcd to your computer and use it in GitHub Desktop.
<script>
function initApp() {
vidyardEmbed.api.addReadyListener(function (data, player) {
vidyardEmbed.api.progressEvents(
function (result) {
var videoTitle = result.player.metadata.name;
var videoUuid = result.player.uuid;
var videoUrl = 'https://share.vidyard.com/watch/' + videoUuid;
var videoDuration = Math.round(
result.player.metadata.chapters_attributes[0].video_attributes
.length_in_seconds
);
var videoDurationInMsec =
result.player.metadata.chapters_attributes[0].video_attributes
.length_in_milliseconds;
var videoCurrentTime = Math.round(result.player.status.currentTime);
var videoCurrentTimeInMsec = result.player.status.currentTime * 1000;
var videoProvider = 'Vidyard';
if (result.event === 1) {
dataLayer.push({
event: 'vidyard.video_start',
video_provider: videoProvider,
video_title: videoTitle,
video_uuid: videoUuid,
video_url: videoUrl,
video_duration: videoDuration,
video_duration_in_msec: videoDurationInMsec,
video_current_time: videoCurrentTime,
video_current_time_in_msec: videoCurrentTimeInMsec,
video_percent: result.event,
});
} else if (result.event === 100) {
dataLayer.push({
event: 'vidyard.video_complete',
video_provider: videoProvider,
video_title: videoTitle,
video_uuid: videoUuid,
video_url: videoUrl,
video_duration: videoDuration,
video_duration_in_msec: videoDurationInMsec,
video_current_time: videoCurrentTime,
video_current_time_in_msec: videoCurrentTimeInMsec,
video_percent: result.event,
});
} else {
dataLayer.push({
event: 'vidyard.video_progress',
video_provider: videoProvider,
video_title: videoTitle,
video_uuid: videoUuid,
video_url: videoUrl,
video_duration: videoDuration,
video_duration_in_msec: videoDurationInMsec,
video_current_time: videoCurrentTime,
video_current_time_in_msec: videoCurrentTimeInMsec,
video_percent: result.event,
});
}
// console.log(result);
},
[1, 10, 25, 50, 75, 90, 100]
);
player.on('pause', function () {
// Prevent firing the event when Vidyard adds the end cards.
var currentTimeInMs = player.status.currentTime * 1000;
var videoDurationInMS =
player.metadata.chapters_attributes[0].video_attributes
.length_in_milliseconds;
if (currentTimeInMs < videoDurationInMS - 1000) {
dataLayer.push({
event: 'vidyard.video_pause',
video_provider: 'Vidyard',
video_title: player.metadata.name,
video_uuid: player.uuid,
video_url: 'https://share.vidyard.com/watch/' + player.uuid,
video_duration: Math.round(
player.metadata.chapters_attributes[0].video_attributes.length_in_seconds
),
video_duration_in_msec: videoDurationInMS,
video_current_time: Math.round(player.status.currentTime),
video_current_time_in_msec: currentTimeInMs,
});
}
// console.log(player);
});
});
}
window.vidyardEmbed
? initApp(window.vidyardEmbed)
: (window.onVidyardAPI = function (vyApi) {
initApp(vyApi);
});
</script>
{
"exportFormatVersion": 2,
"exportTime": "2022-09-19 06:30:24",
"containerVersion": {
"path": "accounts/6005146704/containers/90246344/versions/6",
"accountId": "6005146704",
"containerId": "90246344",
"containerVersionId": "6",
"name": "Vidyard Listener for GTM by Praba Ponnambalam - v1.2",
"container": {
"path": "accounts/6005146704/containers/90246344",
"accountId": "6005146704",
"containerId": "90246344",
"name": "Vidyard Listener",
"publicId": "GTM-WFCTVKR",
"usageContext": ["WEB"],
"fingerprint": "1658571461234",
"tagManagerUrl": "https://tagmanager.google.com/#/container/accounts/6005146704/containers/90246344/workspaces?apiLink=container"
},
"tag": [
{
"accountId": "6005146704",
"containerId": "90246344",
"tagId": "5",
"name": "cHTML - Vidyard Listener",
"type": "html",
"parameter": [
{
"type": "TEMPLATE",
"key": "html",
"value": "<script>\n function initApp() {\n vidyardEmbed.api.addReadyListener(function(data, player) {\n vidyardEmbed.api.progressEvents(function(result) {\n var videoTitle = result.player.metadata.name;\n var videoUuid = result.player.uuid;\n var videoUrl = 'https://share.vidyard.com/watch/' + videoUuid;\n var videoDuration = Math.round(result.player.metadata.chapters_attributes[0].video_attributes.length_in_seconds);\n var videoDurationInMsec = result.player.metadata.chapters_attributes[0].video_attributes.length_in_milliseconds;\n var videoCurrentTime = Math.round(result.player.status.currentTime);\n var videoCurrentTimeInMsec = result.player.status.currentTime * 1000;\n var videoProvider = 'Vidyard';\n if (result.event === 1) {\n dataLayer.push({\n event: 'vidyard.video_start',\n video_provider: videoProvider,\n video_title: videoTitle,\n video_uuid: videoUuid,\n video_url: videoUrl,\n video_duration: videoDuration,\n video_duration_in_msec: videoDurationInMsec,\n video_current_time: videoCurrentTime,\n video_current_time_in_msec: videoCurrentTimeInMsec,\n video_percent: result.event,\n });\n } else if (result.event === 100) {\n dataLayer.push({\n event: 'vidyard.video_complete',\n video_provider: videoProvider,\n video_title: videoTitle,\n video_uuid: videoUuid,\n video_url: videoUrl,\n video_duration: videoDuration,\n video_duration_in_msec: videoDurationInMsec,\n video_current_time: videoCurrentTime,\n video_current_time_in_msec: videoCurrentTimeInMsec,\n video_percent: result.event,\n });\n } else {\n dataLayer.push({\n event: 'vidyard.video_progress',\n video_provider: videoProvider,\n video_title: videoTitle,\n video_uuid: videoUuid,\n video_url: videoUrl,\n video_duration: videoDuration,\n video_duration_in_msec: videoDurationInMsec,\n video_current_time: videoCurrentTime,\n video_current_time_in_msec: videoCurrentTimeInMsec,\n video_percent: result.event,\n });\n }\n // console.log(result);\n },\n [1, 10, 25, 50, 75, 90, 100]);\n player.on('pause', function() {\n // Prevent firing the event when Vidyard adds the end cards.\n var currentTimeInMs = player.status.currentTime * 1000;\n var videoDurationInMS = player.metadata.chapters_attributes[0].video_attributes.length_in_milliseconds;\n if (currentTimeInMs < videoDurationInMS - 1000) {\n dataLayer.push({\n event: 'vidyard.video_pause',\n video_provider: 'Vidyard',\n video_title: player.metadata.name,\n video_uuid: player.uuid,\n video_url: 'https://share.vidyard.com/watch/' + player.uuid,\n video_duration: Math.round(player.metadata.chapters_attributes[0].video_attributes.length_in_seconds),\n video_duration_in_msec: videoDurationInMS,\n video_current_time: Math.round(player.status.currentTime),\n video_current_time_in_msec: currentTimeInMs,\n });\n }\n // console.log(player);\n });\n });\n }\n window.vidyardEmbed ? initApp(window.vidyardEmbed) : (window.onVidyardAPI = function(vyApi) {\n initApp(vyApi);\n });\n</script>"
},
{
"type": "BOOLEAN",
"key": "supportDocumentWrite",
"value": "false"
}
],
"fingerprint": "1663568828537",
"firingTriggerId": ["4"],
"parentFolderId": "6",
"tagFiringOption": "ONCE_PER_EVENT",
"monitoringMetadata": {
"type": "MAP"
},
"consentSettings": {
"consentStatus": "NOT_SET"
}
},
{
"accountId": "6005146704",
"containerId": "90246344",
"tagId": "10",
"name": "GA4 - Event - vidyard.video_*",
"type": "gaawe",
"parameter": [
{
"type": "BOOLEAN",
"key": "sendEcommerceData",
"value": "false"
},
{
"type": "TEMPLATE",
"key": "eventName",
"value": "{{Event}}"
},
{
"type": "LIST",
"key": "eventParameters",
"list": [
{
"type": "MAP",
"map": [
{
"type": "TEMPLATE",
"key": "name",
"value": "video_provider"
},
{
"type": "TEMPLATE",
"key": "value",
"value": "{{dlv - video_provider}}"
}
]
},
{
"type": "MAP",
"map": [
{
"type": "TEMPLATE",
"key": "name",
"value": "video_title"
},
{
"type": "TEMPLATE",
"key": "value",
"value": "{{dlv - video_title}}"
}
]
},
{
"type": "MAP",
"map": [
{
"type": "TEMPLATE",
"key": "name",
"value": "video_url"
},
{
"type": "TEMPLATE",
"key": "value",
"value": "{{dlv - video_url}}"
}
]
},
{
"type": "MAP",
"map": [
{
"type": "TEMPLATE",
"key": "name",
"value": "video_duration"
},
{
"type": "TEMPLATE",
"key": "value",
"value": "{{dlv - video_duration}}"
}
]
},
{
"type": "MAP",
"map": [
{
"type": "TEMPLATE",
"key": "name",
"value": "video_duration_in_msec"
},
{
"type": "TEMPLATE",
"key": "value",
"value": "{{dlv - video_duration_in_msec}}"
}
]
},
{
"type": "MAP",
"map": [
{
"type": "TEMPLATE",
"key": "name",
"value": "video_current_time"
},
{
"type": "TEMPLATE",
"key": "value",
"value": "{{dlv - video_current_time}}"
}
]
},
{
"type": "MAP",
"map": [
{
"type": "TEMPLATE",
"key": "name",
"value": "video_current_time_in_msec"
},
{
"type": "TEMPLATE",
"key": "value",
"value": "{{dlv - video_current_time_in_msec}}"
}
]
},
{
"type": "MAP",
"map": [
{
"type": "TEMPLATE",
"key": "name",
"value": "video_percent"
},
{
"type": "TEMPLATE",
"key": "value",
"value": "{{dlv - video_percent}}"
}
]
},
{
"type": "MAP",
"map": [
{
"type": "TEMPLATE",
"key": "name",
"value": "video_uuid"
},
{
"type": "TEMPLATE",
"key": "value",
"value": "{{dlv - video_uuid}}"
}
]
}
]
},
{
"type": "TEMPLATE",
"key": "measurementId",
"value": "none"
},
{
"type": "TEMPLATE",
"key": "measurementIdOverride",
"value": "G-1234"
}
],
"fingerprint": "1663568800613",
"firingTriggerId": ["9"],
"parentFolderId": "6",
"tagFiringOption": "ONCE_PER_EVENT",
"monitoringMetadata": {
"type": "MAP"
},
"consentSettings": {
"consentStatus": "NOT_SET"
}
}
],
"trigger": [
{
"accountId": "6005146704",
"containerId": "90246344",
"triggerId": "4",
"name": "DOM Ready - Vidyard Pages",
"type": "DOM_READY",
"filter": [
{
"type": "EQUALS",
"parameter": [
{
"type": "TEMPLATE",
"key": "arg0",
"value": "{{cjs - isVidyardPresent}}"
},
{
"type": "TEMPLATE",
"key": "arg1",
"value": "true"
}
]
}
],
"fingerprint": "1658571724416",
"parentFolderId": "6"
},
{
"accountId": "6005146704",
"containerId": "90246344",
"triggerId": "9",
"name": "CE - vidyard_video",
"type": "CUSTOM_EVENT",
"customEventFilter": [
{
"type": "MATCH_REGEX",
"parameter": [
{
"type": "TEMPLATE",
"key": "arg0",
"value": "{{_event}}"
},
{
"type": "TEMPLATE",
"key": "arg1",
"value": "vidyard\\.video_(start|progress|pause|complete)"
}
]
}
],
"fingerprint": "1663568793426",
"parentFolderId": "6"
}
],
"variable": [
{
"accountId": "6005146704",
"containerId": "90246344",
"variableId": "3",
"name": "cjs - isVidyardPresent",
"type": "jsm",
"parameter": [
{
"type": "TEMPLATE",
"key": "javascript",
"value": "// Returns \"true\" if Vidyard palyer(s) embedded on the page\nfunction() {\n var vidplayer = /play.vidyard.com/g;\n for (var e = document.getElementsByTagName('img'), x = e.length; x--;)\n if (vidplayer.test(e[x].src)) {\n return true;\n } return false;\n}"
}
],
"fingerprint": "1658571724416",
"parentFolderId": "6",
"formatValue": {}
},
{
"accountId": "6005146704",
"containerId": "90246344",
"variableId": "11",
"name": "dlv - video_provider",
"type": "v",
"parameter": [
{
"type": "INTEGER",
"key": "dataLayerVersion",
"value": "2"
},
{
"type": "BOOLEAN",
"key": "setDefaultValue",
"value": "false"
},
{
"type": "TEMPLATE",
"key": "name",
"value": "video_provider"
}
],
"fingerprint": "1658627250527",
"parentFolderId": "6",
"formatValue": {}
},
{
"accountId": "6005146704",
"containerId": "90246344",
"variableId": "12",
"name": "dlv - video_title",
"type": "v",
"parameter": [
{
"type": "INTEGER",
"key": "dataLayerVersion",
"value": "2"
},
{
"type": "BOOLEAN",
"key": "setDefaultValue",
"value": "false"
},
{
"type": "TEMPLATE",
"key": "name",
"value": "video_title"
}
],
"fingerprint": "1658627269391",
"parentFolderId": "6",
"formatValue": {}
},
{
"accountId": "6005146704",
"containerId": "90246344",
"variableId": "13",
"name": "dlv - video_url",
"type": "v",
"parameter": [
{
"type": "INTEGER",
"key": "dataLayerVersion",
"value": "2"
},
{
"type": "BOOLEAN",
"key": "setDefaultValue",
"value": "false"
},
{
"type": "TEMPLATE",
"key": "name",
"value": "video_url"
}
],
"fingerprint": "1658627284636",
"parentFolderId": "6",
"formatValue": {}
},
{
"accountId": "6005146704",
"containerId": "90246344",
"variableId": "14",
"name": "dlv - video_duration",
"type": "v",
"parameter": [
{
"type": "INTEGER",
"key": "dataLayerVersion",
"value": "2"
},
{
"type": "BOOLEAN",
"key": "setDefaultValue",
"value": "false"
},
{
"type": "TEMPLATE",
"key": "name",
"value": "video_duration"
}
],
"fingerprint": "1658627301696",
"parentFolderId": "6",
"formatValue": {}
},
{
"accountId": "6005146704",
"containerId": "90246344",
"variableId": "15",
"name": "dlv - video_duration_in_msec",
"type": "v",
"parameter": [
{
"type": "INTEGER",
"key": "dataLayerVersion",
"value": "2"
},
{
"type": "BOOLEAN",
"key": "setDefaultValue",
"value": "false"
},
{
"type": "TEMPLATE",
"key": "name",
"value": "video_duration_in_msec"
}
],
"fingerprint": "1658627317978",
"parentFolderId": "6",
"formatValue": {}
},
{
"accountId": "6005146704",
"containerId": "90246344",
"variableId": "16",
"name": "dlv - video_current_time",
"type": "v",
"parameter": [
{
"type": "INTEGER",
"key": "dataLayerVersion",
"value": "2"
},
{
"type": "BOOLEAN",
"key": "setDefaultValue",
"value": "false"
},
{
"type": "TEMPLATE",
"key": "name",
"value": "video_current_time"
}
],
"fingerprint": "1658627358155",
"parentFolderId": "6",
"formatValue": {}
},
{
"accountId": "6005146704",
"containerId": "90246344",
"variableId": "17",
"name": "dlv - video_current_time_in_msec",
"type": "v",
"parameter": [
{
"type": "INTEGER",
"key": "dataLayerVersion",
"value": "2"
},
{
"type": "BOOLEAN",
"key": "setDefaultValue",
"value": "false"
},
{
"type": "TEMPLATE",
"key": "name",
"value": "video_current_time_in_msec"
}
],
"fingerprint": "1658627373111",
"parentFolderId": "6",
"formatValue": {}
},
{
"accountId": "6005146704",
"containerId": "90246344",
"variableId": "18",
"name": "dlv - video_percent",
"type": "v",
"parameter": [
{
"type": "INTEGER",
"key": "dataLayerVersion",
"value": "2"
},
{
"type": "BOOLEAN",
"key": "setDefaultValue",
"value": "false"
},
{
"type": "TEMPLATE",
"key": "name",
"value": "video_percent"
}
],
"fingerprint": "1658627395643",
"parentFolderId": "6",
"formatValue": {}
},
{
"accountId": "6005146704",
"containerId": "90246344",
"variableId": "19",
"name": "dlv - video_uuid",
"type": "v",
"parameter": [
{
"type": "INTEGER",
"key": "dataLayerVersion",
"value": "2"
},
{
"type": "BOOLEAN",
"key": "setDefaultValue",
"value": "false"
},
{
"type": "TEMPLATE",
"key": "name",
"value": "video_uuid"
}
],
"fingerprint": "1658759811369",
"parentFolderId": "6",
"formatValue": {}
}
],
"folder": [
{
"accountId": "6005146704",
"containerId": "90246344",
"folderId": "6",
"name": "Vidyard Listener",
"fingerprint": "1658571722340"
}
],
"builtInVariable": [
{
"accountId": "6005146704",
"containerId": "90246344",
"type": "PAGE_URL",
"name": "Page URL"
},
{
"accountId": "6005146704",
"containerId": "90246344",
"type": "EVENT",
"name": "Event"
}
],
"fingerprint": "1663569009521",
"tagManagerUrl": "https://tagmanager.google.com/#/versions/accounts/6005146704/containers/90246344/versions/6?apiLink=version"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment