(function checkAudiencesAndExecutePZ(){
// Target audiences
const targetAudiences = ["Fan Shop Audience"];
// Excluded audiences
const excludedAudiences = ["Shooting Audience"];
let tealiumValue = localStorage.getItem("tealium_va_academysports_main");
if (tealiumValue) {
let tealiumObj = JSON.parse(tealiumValue);
console.log("Tealium object: ", JSON.stringify(tealiumObj));
if(!tealiumObj.audiences){
console.log("No audiences found in tealium object.");
return;
}
var audiences = tealiumObj.audiences;
var audienceValues = [];
for (var key in audiences) {
if (key.startsWith("academysports_main_")) {
audienceValues.push(audiences[key]);
}
}
console.log("Audience values: ", audienceValues);
// Checking if all values in targetAudiences are present in audienceValues
var allPresent = targetAudiences.every(val => audienceValues.includes(val));
if(!allPresent){
console.log("All target audiences NOT found in tealium object.");
}else{
console.log("All target audiences found in tealium object.");
}
// Checking if any of the values in excludedAudiences are present in audienceValues
var anyExcludedPresent = excludedAudiences.some(val => audienceValues.includes(val));
if(anyExcludedPresent){
console.log("Excluded audience found in tealium object.");
}
// console.log("All target audiences are present: " + allPresent);
// console.log("Any excluded audiences are present: " + anyExcludedPresent);
// If all target values are present and no excluded values are present, insert the HTML content
if (allPresent && !anyExcludedPresent) {
const htmlContent = `
`;
document.getElementById("fan-gear").innerHTML = htmlContent;
// console.log("All target audiences are present and no excluded audiences are present.");
}
}else{
console.log("No tealium value found in localStorage.");
}
})();