How to execute javascript which is returned from API.
What we have:
- Vast file with XML format of Media Ads for HTML5.
- One API with Javascript response.
- Tried to use "AdVerifications > Verification > JavaScriptResource" tag but can't trigger to execute
Expected:
- Since AdTag is served or whenever Vast file is called, it will trigger to execute Javascript which is responded from API below
- Provide tag to apply this scenario.
Thanks & waiting !!
This is API "/vast/serving/js" with js response.
The purpose is to generate Fingerprint, store at Local Storage of client side and re-execute API twice with value Fingerprint on query param such as "/vast/serving/js?fingerprint=[xyz]".
```
var isStorage;
function generateFingerprintAndScript(adservingUrl) {
var generateFingerprint = function() {
Fingerprint2.get(function(components) {
console.log(components);
var values = components.map(function(component) {
return component.value
});
var murmur = Fingerprint2.x64hash128(values.join(''), 31);
console.log(murmur);
if (isStorage) {
localStorage.setItem("murmur", murmur);
}
generateScript(adservingUrl, murmur);
});
};
var script = document.createElement('script');
script.onload = function() {
if (window.requestIdleCallback) {
requestIdleCallback(function() {
generateFingerprint();
})
} else {
setTimeout(function() {
generateFingerprint();
}, 500)
}
}
;
script.src = "......./sv/js/fingerprint2.min.js";
document.head.appendChild(script);
}
function generateScript(adservingUrl, murmur) {
let itp = true;
if (adservingUrl.includes('/r') || adservingUrl.includes('/tr/clickthrough')) {
window.location.replace(adservingUrl + "&bf=" + murmur + "&itp=" + itp);
} else {
var scriptElement = document.createElement('script');
scriptElement.src = encodeURI(adservingUrl + "&bf=" + murmur + "&itp=" + itp);
document.body.appendChild(scriptElement);
}
}
function generateAd(adUrl) {
if (typeof (Storage) !== "undefined") {
isStorage = true;
if (localStorage.getItem("murmur")) {
generateScript(adUrl, localStorage.getItem("murmur"));
} else {
generateFingerprintAndScript(adUrl);
}
} else {
isStorage = false;
generateFingerprintAndScript(adUrl);
}
}
document.addEventListener('DOMContentLoaded', function() {
console.log("current location:", window.location.href);
generateAd(window.location.href);
});
```