📊Installation DataLayer Prestashop
Partie code
<script>
window.dataLayer = window.dataLayer || [];
</script>{literal}
<script>
function stringToPrice(string){
let prixString = `${string}`;
let prixSansEuro = prixString.replace(" €", "").replace(",", ".");
let prixNum = parseFloat(prixSansEuro);
return prixNum;
};
// Send transaction data with a pageview if available
// when the page loads. Otherwise, use an event when the transaction
// data becomes available.
dataLayer.push({ ecommerce: null }); // Clear the previous ecommerce object.
dataLayer.push({
event: "purchase",
ecommerce: {
transaction_id: '{/literal}{$order.details['reference']}{literal}', // Transaction ID. Required for purchases and refunds.
value: stringToPrice('{/literal}{$order.totals.total['value']}{literal}'), // Total transaction value (incl. tax and shipping)
items: [
{/literal}
{foreach from=$order.products item=product}
{literal}
{
item_name: '{/literal}{$product['product_name']}{literal}', // Name or ID is required.
item_id: '{/literal}{$product['product_reference']}{literal}',
price: stringToPrice('{/literal}{$product['price']}{literal}'),
quantity: stringToPrice('{/literal}{$product['product_quantity']}{literal}'),
},
{/literal}
{/foreach}
{literal}
]
}
}
);
</script>
{/literal}Google Tag Manager
Last updated