1

Because a client doesn't have a dataLayer I'm trying to send scraped revenue data from a thank you page to a Facebook pixel that's being deployed through GTM.

I have Imdocument.querySelectorAll("td")[8].textContent from another useful post but its giving me a string, with spaces and currency symbol.

"
                        $65.00
                    " 

Image of the dev tool Image of the HTML

How can I only get revenue data w/o currency symbol? Just a number.

2 Answers2

0

Just use .replace(" ","") and all the spaces should be replaced.

Marco
  • 1,112
  • 1
  • 14
  • 34
  • 1
    This will remove a single space character. It won't remove tabs or other whitespace characters, and will not touch the currency sign. For whitespace removal see e.g. https://stackoverflow.com/questions/6507056/replace-all-whitespace-characters. – Eike Pierstorff Jan 31 '18 at 17:00
0

You can extract float digit from string with regexp /[+-]?\d+(\.\d+)?/g. In your case it will be like this:

var str = Imdocument.querySelectorAll("td")[8].textContent;
var price = str.match(/[+-]?\d+(\.\d+)?/g)[0];
Victor Leontyev
  • 8,488
  • 2
  • 16
  • 36