Question

Having trouble inserting a pretty simple tracking code into each product page.
I am not having any luck pulling the SKU from the product page to populate the product_id (see below).
I am attempting to do so via a widget - which may be causing an issue, though I have inserted code this way before.

<script type="text/javascript">
        var sidecar = sidecar || {};
        sidecar.product_info = {
        product_id: '1234'
        };
    </script>

Any idea on what code to use so '1234' will dynamically populate with our SKU? Also, product id would be an acceptable substitute if, for whatever reason, it's easier to do so.

Was it helpful?

Solution

you can use below code to get product Id in Product detail page:

<?php $_product = $this->getProduct(); ?>

<script type="text/javascript">
        var sidecar = sidecar || {};
        sidecar.product_info = {
        product_id: '<?php echo $_product->getId();?>'
        };
    </script>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top