How to track revenue for Google Ads

Hi,

I’m using Piwiks Tag Manager and I’m getting conversions sent to Google Ads, but not the revenue from the conversions.
The ecommerce tracking is working, so I’m getting revenue into Piwik.

I’ve tried setting up a variable so I could send data to Google manually as per your guides, but I can’t get the revenue to show up in the variable.

I’ve tried to set the variable up as it used to be in Google tag manager: ecommerce.purchase.actionField.revenue

I’ve also tried to set it up like it is in the Piwik conversion tag: orderDetails.purchase.actionField.revenue

image

Can you help me either get data in the variable or is there an easier way to get conversion value sent to Google Ads?

I could go back to tracking through Google Tag Manager, but then I get a _gcl_au cookie I can’t put in Piwik Consent Manager :confused:

Can you share details about your current setup? Paste the datalayer without using a screenshot, showing the definition of variables (especially those that are working correctly now). Piwik PRO Tag Manager does not support nested datalayer variables yet. Most likely that’s the issue. It can be solved with some custom coding to get the nested values.

Sure :slight_smile:
The datalayer looks like this:

{
  "event": "stg.pageView",
  "gtm.uniqueEventId": 4
}

The variables look like this:

NAME VALUE
0 “config”
1 “AW-10906998861”
2 { “send_to”: “AW-10906998861/hu8CCNipwcoDEM2w7tAo” }
Order ID undefined
Purchase r… undefined
Shipping undefined
addProduct… undefined
Discount undefined
ProductID undefined
ecommerce … { “purchase”: { “actionField”: { “id”: “000001052”, “affiliation”: “Main Website - Main Website Store - Default Store View”, “revenue”: “19.9600”, “coupon”: “”, “tax”: “14.7900”, “shipping”: “39.2000” }, “products”: [ { “name”: “Little One Sticks med frugt, 2x60 g”, “id”: “354003”, “price”: “19.96”, “brand”: “Little One”, “category”: “Kanin og Gnaver/Gnaver- og Kaninfoder”, “list”: “Kanin og Gnaver/Gnaver- og Kaninfoder”, “quantity”: 1 } ] }, “currencyCode”: “DKK” }
View withi… -1
External r… undefined
Form Name undefined
History st… undefined
Page Hostn… www.myvetshop.com
Traffic so… undefined
Old histor… undefined
Form ID undefined
Page Url Indkøbskurv
Form Class… undefined
History so… undefined
Page Path “/checkout/onepage/success/”
Consents { “previous_state”: {}, “current_state”: { “analytics”: 1, “conversion_tracking”: 1, “remarketing”: 1 }, “consent_form_language”: “da” }
Click Clas… undefined
Click Elem… undefined
Old histor… undefined
Leave cont… undefined
Click ID undefined
Page Scrol… { “px”: 0, “%”: 0 }
Found Elem… undefined
Referrer https://payment.quickpay.net/
Click Url undefined
Returning … false
History fr… undefined
Campaign undefined
Event undefined
Form Url undefined
Time on we… undefined
Piwik PRO … function(e) { … }
SPA tracki… “Success Page”
ecommerce { “purchase”: { “actionField”: { “id”: “000001052”, “affiliation”: “Main Website - Main Website Store - Default Store View”, “revenue”: “19.9600”, “coupon”: “”, “tax”: “14.7900”, “shipping”: “39.2000” }, “products”: [ { “name”: “Little One Sticks med frugt, 2x60 g”, “id”: “354003”, “price”: “19.96”, “brand”: “Little One”, “category”: “Kanin og Gnaver/Gnaver- og Kaninfoder”, “list”: “Kanin og Gnaver/Gnaver- og Kaninfoder”, “quantity”: 1 } ] }, “currencyCode”: “DKK” }
gtm.start 1674028583535
gtm.unique… 3

The ecommerce tag that’s working now is:
var _paq = _paq || ;
var orderDetails = {{ ecommerce object }};
var products = orderDetails.purchase.products;
var order_id = orderDetails.purchase.actionField.id;
var grand_total = orderDetails.purchase.actionField.revenue;
var tax = parseInt(orderDetails.purchase.actionField.tax);
var shipping = orderDetails.purchase.actionField.shipping;
var discount = orderDetails.purchase.actionField.coupon;

products.forEach(function(product){
  _paq.push(["addEcommerceItem",product.id.toString(), product.name, product.category, product.price, product.quantity])

});
_paq.push([“trackEcommerceOrder”,order_id, grand_total, tax, shipping, discount]);

The only variable I have that’s working is the ecommerce object with Data layer variable name: ecommerce

Apart from the beforementioned variables I haven’t gotten to work, I’ve also tried making a tag based on the Piwik conversion tag, that didn’t work:

var _paq = _paq || [];
var orderDetails = {{ ecommerce object }};
var grand_total = orderDetails.purchase.actionField.revenue;

_paq.push([grand_total]);

Let me know if you need any more data, I’ll happily provide :slight_smile:

OK, it looks all fine. I only don’t get what do you want to achieve with the second tag? Once I have that info, I can suggest some solution.

Well I want to get the conversion value on Google Ads conversions sent to Google Ads.

Currently all orders have 0 as value because I can’t get my Purchase revenue variable to have the value in it, so I don’t have anything to send through the Google Ads Conversion Tracking tag

image

Hi. Try with the following custom variable:

Here’s the code. You can adjust it to your needs:

function() {
  var orderDetails = {{ ecommerce }};

  if (typeof orderDetails !== 'undefined')
    return orderDetails.purchase.actionField.revenue;
  else
    return null;
}

That worked :smiley: Thank you so much!

Hi,
I’ve used this code, but I’m getting a lot of javascript errors on my product pages now saying stuff like:

Failed to evaluate variable - ProductID: Cannot read properties of undefined (reading ‘products’)
Failed to evaluate variable - Discount: Cannot read properties of undefined (reading ‘actionField’)

I’m guessing it’s because the variable is trying to read when it shouldn’t be, but I don’t know javascript so I don’t know how to include a check on wether “ecommerce” includes the actionField or not.

Anyone who can help me out?

@kuba Any chance you can help me on how to avoid the javascript errors this solution is giving?

@Bacterfield I’m afraid that it would be hard to set it up without JavaScript knowledge. For the mentioned error, most likely your dataLayer object doesn’t have the following property.

My code example included a basic check:

if (typeof yourvariable !== 'undefined')

You could use it to check other vars (even those with nested values).