Reputation: 11
Im trying to create a custom conversion event based on item_id (SKU) in Google Analytics 4. I have a purchase event that correctly reports the number of purchases and the items purchased with item ids under the Montesation page in GA4.
Based on this, I want to create custom conversion events for different item ids so I can optimize campaigns based on purchases of specific SKUs. What Im trying to achieve is a way to optimize campaigns for purchases of specific SKUs/item ids.
In the GA4 interface, I thought I could do: Admin -> Data Display -> Events -> Create event -> Create -> event_name = "purchase", and item_id contains "SKU_XYZ", but that does not seem work. The new event does not show up. It seems like it is not possible to create conditions based on item id, even if that parameter is shown in the list of parameters when you Create events based on other events.
Any idea how to achieve the above?
Upvotes: 1
Views: 163
Reputation: 21
I don't know why, but Google says "You can't generate or modify events based on parameters from the items array (e.g., item_brand, item_name, item_id) when you use gtag.js."
In may case, on a Wordpress site with WooCommerce that is using gtag.js, to solve this problem I added the following code to a custom WooCommerce order-details.php page (copied to your-theme/woocommerce/order) to create a unique event that is separate from the purchase event.
// Send gtag.js event with product_id and order total
foreach ( $order_items as $order_item ) { ?>
<script>
gtag ('event', 'order_details_presented', {
'product_id' : <?php echo $order_item['product_id']; ?>,
'value' : <?php echo $order->total; ?>
});
</script>
<?php }
The Website now sends an event called order_details_presented whenever the order-details.php is executed with the Parameters product_id and value. Additional Parameters can easily be added if needed by including them in the gtag call.
Then to create a unique event for each product_id that you want to track in GA4, go to Admin->Events and click Modify Event. To configure the modified event click Create, give it a unique Modification name and put your Value in for the product_id like below (The product_id I wanted to track as a Key event was 16304).
You will need to configure a modified event for each product_id you want to track. Your New Value for event_name should be unique for the product, or a category of products that you want to track together.
Since in WooCommerce order-details.php is used on more than just the order-received page I added the third matching condition so my product_id event will only create a key event when the customer reaches the /checkout/order-received/ page after an order is placed.
In my case, I will be using these events as Key events in Google Ads, so the last step in GA4 is to go to Admin->Key events, click New key event, and enter the new event name to begin tracking it as a Key event. Then I changed the counting method to Once per session so it will only be counted once if the user refreshes the page or navigates away and then comes back.
Upvotes: 0