We have a new site which now uses a SPA set up, so Target has followed suit.
The issue I'm having is when I inject my code via Target, it works fine on first load, but if the user navigates back to that page/view, the code will be injected again (and the original injection is still in the DOM)
Is there a way to get around this? I just want one injection.
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Hi @kamranali,
I am unsure why this is happening with the Target for SPA, but you can add some code that only injects your code if it still needs to be added. In your custom code within Target, add a flag such as this example:
// Check if code has already been loaded
if (window.offerLoaded === true) {
return;
}
// Set flag to true to indicate code has been loaded
window.offerLoaded = true;
This should prevent the code from injecting twice from your specific activity.
I suggest opening a client care ticket and having them see if they can provide you with a more permanent fix, so you do not need to add a flag to each activity/custom code.
email to open a ticket: ttclientcare@adobe.com
I hope that helps.
Matthew Ravlich | ACG Digital | albertacg.com
Hi @kamranali,
I am unsure why this is happening with the Target for SPA, but you can add some code that only injects your code if it still needs to be added. In your custom code within Target, add a flag such as this example:
// Check if code has already been loaded
if (window.offerLoaded === true) {
return;
}
// Set flag to true to indicate code has been loaded
window.offerLoaded = true;
This should prevent the code from injecting twice from your specific activity.
I suggest opening a client care ticket and having them see if they can provide you with a more permanent fix, so you do not need to add a flag to each activity/custom code.
email to open a ticket: ttclientcare@adobe.com
I hope that helps.
Matthew Ravlich | ACG Digital | albertacg.com
Hi @kamranali,
I agree with @Matthew_Ravlich_ACG. In the code you have to check if the offer has already been injected or not - and react accordingly.
Best regards
Views
Like
Replies
Views
Likes
Replies