-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from Wikia/IW-130
IW-130 | User-Intended plays recognition module
- Loading branch information
Showing
4 changed files
with
95 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
function wikiaJWPlayerUserIntendedPlayControl(isInitiallyUserIntendedPlay, playerInstance, tracker, willAutoplay) { | ||
var isUserIntendedPlay = null; | ||
var isUserIntendedByUnmuting = false; | ||
var wasPausedByUserInteraction = false; | ||
var customDimensionNumber = 39; | ||
var customDimensionValueWhenIntended = 'user-intended'; | ||
var customDimensionValueWhenNotIntended = 'not-user-intended'; | ||
|
||
function setUserIntendedPlay(isUserIntended) { | ||
if (isUserIntendedPlay === isUserIntended) { | ||
return; | ||
} | ||
|
||
isUserIntendedPlay = isUserIntended; | ||
|
||
if (typeof tracker.setCustomDimension !== 'function') { | ||
return; | ||
} | ||
|
||
tracker.setCustomDimension( | ||
customDimensionNumber, isUserIntended ?customDimensionValueWhenIntended : customDimensionValueWhenNotIntended | ||
); | ||
} | ||
|
||
function onPause(data) { | ||
if (data.pauseReason === 'interaction') { | ||
wasPausedByUserInteraction = true; | ||
} | ||
} | ||
|
||
function onPlay() { | ||
if (wasPausedByUserInteraction) { | ||
setUserIntendedPlay(true); | ||
} | ||
} | ||
|
||
function onFullScreen() { | ||
setUserIntendedPlay(true); | ||
} | ||
|
||
function onUnmute() { | ||
setUserIntendedPlay(true); | ||
isUserIntendedByUnmuting = true; | ||
} | ||
|
||
function onMute() { | ||
if (isUserIntendedPlay && isUserIntendedByUnmuting) { | ||
setUserIntendedPlay(false); | ||
} | ||
} | ||
|
||
function onVideoThumbnailInsidePlayerClicked() { | ||
setUserIntendedPlay(true); | ||
} | ||
|
||
function init() { | ||
playerInstance.on('mute', function () { | ||
if (playerInstance.getMute()) { | ||
onMute(); | ||
} else { | ||
onUnmute(); | ||
} | ||
}); | ||
|
||
playerInstance.on('pause', onPause); | ||
playerInstance.on('play', onPlay); | ||
playerInstance.on('fullscreen', onFullScreen); | ||
|
||
playerInstance.on('relatedVideoPlay', function (data) { | ||
if (!data.auto) { | ||
onVideoThumbnailInsidePlayerClicked(); | ||
} | ||
}); | ||
|
||
if (!willAutoplay) { | ||
setUserIntendedPlay(true); | ||
} else if (isInitiallyUserIntendedPlay) { | ||
setUserIntendedPlay(true); | ||
} else { | ||
setUserIntendedPlay(false); | ||
} | ||
} | ||
|
||
playerInstance.once('ready', init); | ||
} | ||
|
||
window.wikiaJWPlayerUserIntendedPlayControl = wikiaJWPlayerUserIntendedPlayControl; |