Answer the question
In order to leave comments, you need to log in
Get id for Google Tag Manager from Woocommerce?
Good afternoon.
There was a need to execute a script that will send data about a completed purchase to the CRM associated with Google Tag Manager, the script itself looks like this:
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'ecommerce': {
'currencyCode': 'USD',
'purchase': {
'actionField': {
'id': 'TransactionID',
'revenue': 120,
},
'products': [{
'name': 'Product 1',
'id': 'ID1',
'price': '23.5',
'sku': '6517',
'quantity': 2
},{
'name': 'Product 2',
'id': 'ID3',
'price': '23.5',
'sku': '2117',
'quantity': 1
}]
}
},
'event': 'purchaseEEC',
});
</script>
add_shortcode('twit', 'gb_twit');
function gb_twitro() {
$product_id = get_the_ID();
$product = wc_get_product( $product_id );
return "
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'ecommerce': {
'currencyCode': 'USD',
'purchase': {
'actionField': {
'id': 'TransactionID',
'revenue': 120,
},
'products': [{
'name': 'Product 1',
'id': 'ID1',
'price': '". $product->get_sale_price(); ."',
'sku': '6517',
'quantity': 2
},{
'name': 'Product 2',
'id': 'ID3',
'price': '23.5',
'sku': '2117',
'quantity': 1
}]
}
},
'event': 'purchaseEEC',
});
</script>";
}
add_shortcode('twitro', 'gb_twitro');
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question