Answer the question
In order to leave comments, you need to log in
What plugin is the most convenient with woocommerce to transfer product data to Google Analytics?
Tell me through which plugin to connect Google analytics with woocommerce.
It is necessary to transfer data about the ordered products:
unique transaction
ID product ID
total purchase price product
name product
price product
quantity
Answer the question
In order to leave comments, you need to log in
The solution above turned out to be good. But after rummaging for an hour in the google documentation, I found an alternative. I'll just post it here. Maybe it will come in handy for someone.
Suitable for those who are not afraid to get into the wordpress
code The code must be placed in the functions.php file
function devise_wc_ga_integration( $order_id ) {
$order = new WC_Order( $order_id ); ?>
<script type="text/javascript">
ga('require', 'ecommerce', 'ecommerce.js');
ga('ecommerce:addTransaction', {
'id': '<?php echo $order_id;?>',
'affiliation': '<?php echo get_option( "blogname" );?>',
'revenue': '<?php echo $order->get_total();?>',
'shipping': '<?php echo $order->get_total_shipping();?>',
'tax': '<?php echo $order->get_total_tax();?>',
'currency': '<?php echo get_woocommerce_currency();?>'
});
<?php
if ( sizeof( $order->get_items() ) > 0 ) {
foreach( $order->get_items() as $item ) {
$product_cats = get_the_terms( $item["product_id"], 'product_cat' );
if ($product_cats) {
$cat = $product_cats[0];
} ?>
ga('ecommerce:addItem', {
'id': '<?php echo $order_id;?>',
'name': '<?php echo $item['name'];?>',
'sku': '<?php echo get_post_meta($item["product_id"], '_sku', true);?>',
'category': '<?php echo $cat->name;?>',
'price': '<?php echo $item['line_subtotal'];?>',
'quantity': '<?php echo $item['qty'];?>',
'currency': '<?php echo get_woocommerce_currency();?>'
});
<?php
}
} ?>
ga('ecommerce:send');
</script>
<?php }
add_action( 'woocommerce_thankyou', 'devise_wc_ga_integration' );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question