Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alewolf/8f7adda46d46a89f85f3ee79d00f35ba to your computer and use it in GitHub Desktop.
Save alewolf/8f7adda46d46a89f85f3ee79d00f35ba to your computer and use it in GitHub Desktop.
create an event for Google Analytics custom dimensions in woopt WooCommerce Pixel Manager
<?
add_action('wp_head', function () {
?>
<script>
jQuery(document).on('wooptpmAddToCart', function (event, product) {
gtag('event', 'add_to_cart', {
"send_to" : wooptpmDataLayer.pixels.google.analytics.universal.property_id, // this is important to scope it to only GA UA and not send it to other properties
'ecomm_prodid': product.dyn_r_ids[wooptpmDataLayer.pixels.google.analytics.id_type], // you must make sure that the same ID type is being used for GA and Google Ads
'ecomm_pagetype': wooptpmDataLayer.shop.page_type,
'ecomm_totalvalue': product.quantity * product.price,
});
});
</script>
<?php
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment