mardi 3 août 2021

Javascript IF/Else in GTM Variable

I am trying to use GTM & custom Javascript to dynamically insert structured mark-up to a page depending on the text that is displayed at a certain position on the page (this changes every few weeks).

To do this I am trying to use If/Else but it results in undefined each time. If have already created a variable that is working correctly and pulling the required text from the page .

I have so far:

function () {
  
  var eventloc = ;
var customeventloc;

if (eventloc === Manchester) {
 customeventloc = 'Manchester details goes here';
}
else 
  if (eventloc === Liverpool) {
   customeventloc = 'Liverpool details goes here';
  }
else
  if (eventloc === Leeds) {
    customeventloc = 'Leeds details goes here';
  }
else
  if (eventloc === Birmingham) {
    customeventloc = 'Birmingham details goes here';
  }
else {
  customeventloc = 'some other details goes here';
}

return customeventloc;

}

This might be straightforward, but I just can't seem to get this to work.

Aucun commentaire:

Enregistrer un commentaire