let detectProgramPage = () => {
if (document.location.href.includes('/programs/')) {
let getAccessNowButton = document.querySelector('.access-screen--btn');
if (getAccessNowButton) {
if (!getAccessNowButton.classList.value.includes('touched')) {
getAccessNowButton.href = '/pages/registration'
getAccessNowButton.classList.add('touched')
}
}
let myPlayer = document.querySelector('.plyr__video-wrapper video');
if (myPlayer) {
if (!myPlayer.classList.value.includes('touched')) {
let userGuest = document.querySelector('body').dataset.guest == 'true'
let userID = document.querySelector('body').dataset.userId
let userEmail = document.querySelector('body').dataset.userEmail
let programTitleHtml = document.querySelector('.cbt-header')
let programTitle = null
if (programTitleHtml) {
programTitle = programTitleHtml.innerText
}
let programUrl = location.href
let chapterName = null
let currentTime = parseFloat(myPlayer.currentTime / 60).toFixed(2).replace('.',':')
if (new URL(location.href).searchParams.get('cid')) {
chapterName = document.querySelector('.chapter-item-active.chapter-item .chapter-item--title.stable').innerText.trim()
}
var percentageCompleted = 0;
var totalLength;
var videoStarted, videoTwentyFive, videoFifty, videoSeventyFive, videoComplete = false;
if (!userGuest) {
let userVisitedPage = {
'user_email': userEmail,
'user_id': userID,
'program_title': programTitle,
'program_url': programUrl,
"date": new Date().toLocaleString("en-GB", {timeZone: "Europe/London", year: 'numeric', month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit' })
}
console.log(userVisitedPage)
axios.post('https://hooks.zapier.com/hooks/catch/6826732/ogkprcv/',JSON.stringify(userVisitedPage))
.then(function (response) {
console.log(response)
})
}
if (!userGuest) {
myPlayer.ontimeupdate = function() {
let newCapterName = document.querySelector('.chapter-item-active.chapter-item .chapter-item--title.stable')
if (newCapterName) {
newCapterName = document.querySelector('.chapter-item-active.chapter-item .chapter-item--title.stable').innerText.trim()
}
if (chapterName !== newCapterName) {
chapterName = newCapterName
percentageCompleted = 0;
totalLength = myPlayer.duration / 60;
videoStarted = false
videoTwentyFive = false
videoFifty = false
videoSeventyFive = false
videoComplete = false;
}
totalLength = myPlayer.duration / 60;
percentageCompleted = ((myPlayer.currentTime / 60) / totalLength) * 100;
if ((!videoStarted) && (percentageCompleted > 0)) {
console.log('VIDEO_STARTED');
let userVideoStarted = {
'user_email': userEmail,
'user_id': userID,
'program_title': programTitle,
'program_url': programUrl,
"video_length": totalLength,
"video_progress": 0,
"date": new Date().toLocaleString("en-GB", {timeZone: "Europe/London", year: 'numeric', month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit' })
}
if (chapterName) {
userVideoStarted['program_title'] += ` | ${chapterName}`
}
videoStarted = true;
console.log(userVideoStarted)
axios.post('https://hooks.zapier.com/hooks/catch/6826732/ogkprcv/',JSON.stringify(userVideoStarted))
.then(function (response) {
console.log(response)
})
}
if ((!videoTwentyFive) && (percentageCompleted > 25)) {
videoTwentyFive = true;
currentTime = parseFloat(myPlayer.currentTime / 60).toFixed(2).replace('.',':');
console.log('VIDEO_25');
let userVideo25 = {
'user_email': userEmail,
'user_id': userID,
'program_title': programTitle,
'program_url': programUrl,
"video_length": totalLength,
"video_time": currentTime,
"video_progress": 25,
"date": new Date().toLocaleString("en-GB", {timeZone: "Europe/London", year: 'numeric', month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit' })
}
if (chapterName) {
userVideo25['program_title'] += ` | ${chapterName}`
}
console.log(userVideo25)
axios.post('https://hooks.zapier.com/hooks/catch/6826732/ogkprcv/',JSON.stringify(userVideo25))
.then(function (response) {
console.log(response)
})
}
if ((!videoFifty) && (percentageCompleted > 50)) {
videoFifty = true;
currentTime = parseFloat(myPlayer.currentTime / 60).toFixed(2).replace('.',':');
console.log('VIDEO_50');
let userVideo50 = {
'user_email': userEmail,
'user_id': userID,
'program_title': programTitle,
'program_url': programUrl,
"video_length": totalLength,
"video_time": currentTime,
"video_progress": 50,
"date": new Date().toLocaleString("en-GB", {timeZone: "Europe/London", year: 'numeric', month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit' })
}
if (chapterName) {
userVideo50['program_title'] += ` | ${chapterName}`
}
axios.post('https://hooks.zapier.com/hooks/catch/6826732/ogkprcv/',JSON.stringify(userVideo50))
.then(function (response) {
console.log(response)
})
console.log(userVideo50)
}
if ((!videoSeventyFive) && (percentageCompleted > 75)) {
videoSeventyFive = true;
currentTime = parseFloat(myPlayer.currentTime / 60).toFixed(2).replace('.',':');
console.log('VIDEO_75');
let userVideo75 = {
'user_email': userEmail,
'user_id': userID,
'program_title': programTitle,
'program_url': programUrl,
"video_length": totalLength,
"video_time": currentTime,
"video_progress": 75,
"date": new Date().toLocaleString("en-GB", {timeZone: "Europe/London", year: 'numeric', month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit' })
}
if (chapterName) {
userVideo75['program_title'] += ` | ${chapterName}`
}
console.log(userVideo75)
axios.post('https://hooks.zapier.com/hooks/catch/6826732/ogkprcv/',JSON.stringify(userVideo75))
.then(function (response) {
console.log(response)
})
}
if ((!videoComplete) && (percentageCompleted > 99)) {
videoComplete = true;
currentTime = parseFloat(myPlayer.currentTime / 60).toFixed(2).replace('.',':');
console.log('VIDEO_100');
let userVideo100 = {
'user_email': userEmail,
'user_id': userID,
'program_title': programTitle,
'program_url': programUrl,
"video_length": totalLength,
"video_time": currentTime,
"video_progress": 100,
"date": new Date().toLocaleString("en-GB", {timeZone: "Europe/London", year: 'numeric', month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit' })
}
if (chapterName) {
userVideo100['program_title'] += ` | ${chapterName}`
}
console.log(userVideo100)
axios.post('https://hooks.zapier.com/hooks/catch/6826732/ogkprcv/',JSON.stringify(userVideo100))
.then(function (response) {
console.log(response)
})
}
}
}
myPlayer.classList.add('touched')
}
}
}
setTimeout(() => detectProgramPage(), 500)
}
detectProgramPage()