Home > Blockchain >  GTM variable DOM element image URL
GTM variable DOM element image URL

Time:06-14

I added dynamic structured data for recipes to my webiste, but the variable for the recipe image is not displayed correctly. The data layer autmatically adds two backslashes in front of every slash of the url. This causes problems with the rich snippet:

Screenshot DOM variable

Source code

Error in rich results test

rendered HTML in GTM preview

I am no programmer, just an SEO and my skills in HTML are very basic, so I would be very happy if anyone could help me out with that. Thanks

Julia

CodePudding user response:

It's called escaping. the slashes are dual-meaning, they act both as a regular character and also as a programing indicator, so when you want to use them as regular char - you have to "escape" the programing meaning by adding a backslash before.

CodePudding user response:

If you want to make sure, that the escaping is removed in the rendered HTML, just create an additional JS var in GTM:

function removeEscaping() {
  var escapedUrl = {{}}, //your DOM var
      cleanedUrl = escapedUrl.replace('\\','');
  return cleanedUrl;
}

This should do the job...

  • Related