Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

The 1st edition of the Target Community Lens newsletter is out now! Click to the right to find all the latest updates

Code is duplicating on SPA set up


Level 1

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.

2 Replies


Level 2

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) {
  // 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: 


I hope that helps.


Community Advisor

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

The ultimate experience is back.

Join us in Vegas to build skills, learn from the world's top brands, and be inspired.

Register Now