Dynamically set currency value from Label in facebook pixel tracking in JavaScript

nauna
 
on May 17, 2021 03:11 AM
720 Views

hello,

how to add fb pixel event code on page like

https://developers.facebook.com/docs/facebook-pixel/implementation/conversion-tracking/#standard-events

the 30.00 i have to pass thru Label1 value

<script>
    fbq('track', 'Purchase', {currency: "USD", value: 30.00});
</script>

pls advice

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on May 17, 2021 06:11 AM

Hi nauna,

Use window.onload function. Get the label value and assign to the JavaScript object.

<script type="text/javascript">
    window.onload = function () {
        var currencyValue = parseFloat(document.getElementById('Label1').innerHTML);
        fbq('track', 'Purchase', { currency: "USD", value: currencyValue });
    };
</script>

Or set it when required.