google-tag-managerjson-ldgoogle-rich-snippetsstructured-data

How to replace comma with a dot in GTM for JSON structured data?


I am noob with structured data implementation and don't have any code knowledge. I have been looking for a week how to solve a warning with price in Google structured data testing tool.

My prices are with a comma which is not accepted by Google. By checking the http://schema.org/price it tells me that "Use '.' (Unicode 'FULL STOP' (U+002E)) rather than ',' to indicate a decimal point. Avoid using these symbols as a readability separator."

I have a CSS variable element #PdtPrixRef named in a variable "Product-price" with a comma "12.5" but I can't find how to replace it in my structured data with the value "12.5"... Someone to help me?

Hereafter my actual script :

My actual GTM script

Should I add something to my script or making an VARIABLE (Custom Js)? I think it's something like

value.replace(",", ".")

But I do't know how to write the full proper function from beginning to end...


Solution

  • Yes you can just create a Custom JavaScript Variable

    enter image description here

    Here is the code

    function(){
        var price = {{Product-price}};
        return price.replace("," , ".");
    }
    

    Then using this variable to your JSON-LD script.