2

I have a website that needs to serve Ad units from a specific Ad program when there are specific UTM parameters in the URL, and the user needs to see these Ad units as long as they stay on the website. However, when a user comes without those UTM parameters, I can serve any Ads I want, which I would want to be Google AdSense.

This was done rather simply using PHP and cookies. However, this does not work when the website is cached and the HTML code cannot change.

Javascript came to mind, but I have a problem making it work.

I now have a working cookie which is created from UTM parameters, and then I just need to serve pieces of Ad code (Adsense script, the other Ad program script, and Ad Units) based on the values in the cookie, something like this:

var cookievalue = Cookies.get('utm_source');    
if (cookievalue == "something") {
      serve the NOT Adsense code
    } else {
      serve the Adsense code
    }

any ideas how to do that so that the serving scripts are added properly to the code?

Tadoch
  • 21
  • 2
  • Just extract utm from url parameters and store it in sessionStorage instead of cookies. Then you can use it to serve your ads as long sessionStorage exist. – CODE_17 Oct 30 '20 at 23:16
  • Thanks, will do. however, my problem is really the correct injecting of Ad codes so that they serve ads properly – Tadoch Oct 30 '20 at 23:19

0 Answers0