Hello all,
I've been running into an issue with getting the 'else' portion of a block of code to fire in one of my activities and wanted to see if anyone had any insight or could point me in the right direction. I have experience as a front-end dev so am somewhat familiar with JS, but admittedly have not kept up with it as I've moved into a full-time A/B testing role, so I'm definitely rusty.
Basically we're trying to get our content to change in Target based on a variable value. The custom code in Target does fire, however it fires even if the variable value is incorrect. I'm including a screenshot of what I'm seeing, but the 'Modified with Target...' copy should not be displaying along with the banner image, as the ui.userInfo.bannerName value is set to HYSA 2 but was set to 'HYSA 1' in this case upon launching this site in our dev environment.
The code I'm using in my Target activity is below:
<script>
adobe.target.getOffer({
"mbox": "target-global-mbox",
"success": function(offer) {
console.log('success');
if ('ui.userInfo.bannerName == "HYSA 1"'){
console.log('param works');
$('#PromoBanner #AmexPromoBanner #adContent .cta #PromoBannerTitle').text('Modified with Target - 23-6484790928A');
$('#PromoBanner #AmexPromoBanner #heroImage').attr("src", "https://www.transunion.com/content/dam/transunion/global/consumer/images/testing/amex/planit.jpg");
} else {
console.log('param does not works');
$('#PromoBanner #AmexPromoBanner #heroImage').attr("src", "https://amexccvd-canary.slo-devweb.truelink.com/sites/CreditView/assets/images/promo-banner/mycred.p...");
}
},
"error": function(status, error) {
console.log('error');
},
"timeout": 2000
});
</script>
Please let me know if anyone can help - thank you!
Dan
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Hi @ddiaczun,
if I see it correctly your problem is that the condition of ui.userInfo.bannerName == "HYSA 1" is met - but you see in the Console the value HYSA 2, right? If so, it looks to me like it's a timing issue - that the if condition in the script is executed too early.
Hope I have understood your problem correctly.
Best regards
Hi @ddiaczun,
if I see it correctly your problem is that the condition of ui.userInfo.bannerName == "HYSA 1" is met - but you see in the Console the value HYSA 2, right? If so, it looks to me like it's a timing issue - that the if condition in the script is executed too early.
Hope I have understood your problem correctly.
Best regards
That seems to be the case - we have a set of about 10 values for ui.userInfo.bannerName however the 'else' condition does not fire on any of them.
In this case would I need a timer function to check for the correct value every 50-100 milliseconds? I'm not very familiar with how the ui.userInfo.bannerName was created on our back-end so unfortunately cannot provide much additional context at the moment, but I can reach out to the engineering team that worked on this.
Please let me know when you've had a moment to review - thanks!
Views
Like
Replies