This code snippet is a JavaScript function designed to embed a video player from ivm.antenaplay.ro onto a webpage, handling GDPR consent requirements. Let’s break down its functionality step-by-step:
1. insertIvmEmbed(ivmwrapperid) Function:
Purpose: This function is the core of the embedding process. It dynamically creates a tag, sets its src attribute to a URL that includes video ID, dimensions, and other parameters, and then appends the script to the document.body.
ivmwrapperid: This parameter seems to be a flag indicating whether to embed the player. The ternary operator (1 == ivmwrapperid) ? 1 : 0 effectively converts any non-1 value to 0. This is likely used to control whether the embedding happens.
str.dataset.guid: This retrieves the value of the data-guid attribute from the element referenced by str. This guid is likely the unique identifier of the video to be embedded.
w and h: these variables represent the desired width and height of the embedded video player.
playRelated: A boolean value determining whether related videos should be played after the current one. divid: The ID of the
ads: A boolean value indicating whether ads should be enabled.src Attribute Construction: The src attribute of the tag is dynamically constructed with the following parameters:
//ivm.antenaplay.ro/js/embedweegoo.js: the base URL of the embedding script.
id=" + str.dataset.guid: The video ID.
&width=" + w: The width of the player.
&height="+h: The height of the player.
&next=" + playRelated: Whether to play related videos.
&autoplay=0: Disables autoplay.
&wide=true: Sets the player to wide mode. &muted=1: Mutes the player.
&divid=" + divid: The ID of the container div.
&ads=" + (ads?1:0): Enables ads if the ads variable is true.
document.body.appendChild(s): Adds the newly created tag to the end of the of the document.This triggers the loading and execution of the embedding script.
2. GDPR Consent Handling:
setInterval: The code uses setInterval to repeatedly check for the availability of the window.tcfapi object. This object is provided by a Consent Management Platform (CMP) and is used to access GDPR consent data.
cnt: A counter to prevent the setInterval from running indefinitely.
clearInterval(consentSetInterval): Stops the setInterval onc the window.tcfapi object is found or after 60 seconds (to prevent infinite loops).
window.__tcfapi( 'addEventListener', 2, function( tcData,listenerSuccess ) { ... });: This is the core of the GDPR handling. It registers an event listener with the CMP to receive consent data.
'addEventListener', 2: Registers a listener for event ID 2, which corresponds to the "TC Data" event (consent data).
tcData: An object containing the consent data.
listenerSuccess: A boolean indicating whether the listener was successfully registered.
* tcData.eventStatus === 'tcloaded' || tcData.eventStatus === 'useractioncomplete': Checks if the consent data has been fully loaded (`tcl
