Woocommerce Data Layer dynamic values for Matomo Tag Manager - woocommerce

In order to track Ecommerce interactions using the Matomo Tag Manager with Data Layers I need to insert this Code as described in the documentation (step 4): https://matomo.org/faq/tag-manager/faq_35847/
window._mtm = window._mtm || [];
window._mtm.push({
'event': 'purchase',
'ecommerce': {
'purchase': {
'id': 'dynamic value',
'revenue': 'dynamic value',
'orderSubTotal': 'dynamic value',
'tax': 'dynamic value',
'shipping': 'dynamic value',
'discount': 'dynamic value',
}
}
});
I have two questions:
Should this code be added to the header of my Wordpress Site?
The "dynamic value" needs to be replaced with the actual values of the commerce interaction. Any chance someone could tell me what to insert?
I'd be very thankful for some hints how to find these values.
Thank you!
Cheers
Bilal
As I'm not a developer I'm a bit confused. I found some code like "get_id()" but I don't know how to process this.

Related

Tracking with Google Tag Manager Ecommerce to Analytics

I need your help about GTM and UA.
Like this exemple i catch the Event in Google Analytics that's work fine :
// Measure the removal of a product from a shopping cart.
dataLayer.push({
'event': 'removeFromCart',
'ecommerce': {
'remove': { // 'remove' actionFieldObject measures.
'products': [{ // removing a product to a shopping cart.
'name': 'Triblend Android T-Shirt',
'id': '12345',
'price': '15.25',
'brand': 'Google',
'category': 'Apparel',
'variant': 'Gray',
'quantity': 1
}]
}
}
});
In Analytics i can catch the "Event" but where is products data ?
Thanks in advance for your help.
The products data is in the datalayer. You can set set the GA tag to read the dataLayer (alternatively you can set it to use an E-commerce-Variable containing the product data). This is just not very visible in the documentation, you need to click the little green arrow below the code example to expand the description of how to configure your tag (the example assumes you are using and event to send e-commerce data):
If you use a GA setting variable you might need to click "override settings" in the GA tag first.

How can I get a value from the ecommerce array as a custom variable in Tag Manager?

I have a site that has Tag Manager installed and I have the following in the data layer:
window.dataLayer.push({
'ecommerce': {
'currencyCode': 'USD',
'purchase': {
'actionField': {
'id': '2851743',
'affiliation': 'MOS: 8',
'revenue': 75.00,
'tax': .00,
'shipping': 12.00,
'coupon': ''
},
'products': [
{
'brand': 'Existing Customer',
'name': 'Product Name',
'id': '1216M18',
'price': '63',
'category': 'Tickets',
'variant': '12/16/17 2pm',
'quantity': '1',
'dimension2': 'Saturday'
}
]
}
}
});
I have a tag in tag manager that is a non-analytics tag and I need to pull values from the data layer, such as ecommerce.purchase.actionField.revenue or ecommerce.purchase.products.id and use them as a custom variable in Tag Manager so they can be added to my tag.
However I can't seem to get the values using the format: ecommerce.purchase.actionField.revenue
I am putting this inside of the "Data Layer Variable Name" field on the variable configuration window in the variables section of Tag Manager.
Is there another way I can get these items?
Thanks!
Generally, referring to those values in the enhanced ecomm spec will be highly flawed. I would strongly suggest you do the following:
In a second dataLayer push, send the appropriate revenue, product IDs, etc that are relevant for this second tag
dataLayer.push({event:"secondRevenue", revenue: "XXX", products: [XXX]})
Set a trigger to fire your alternative tag on event = "secondRevenue"
Create variables that are equal to dataLayer.revenue and dataLayer.products and associate/consume them in your second tag
ecommerce.purchase.products.id won't work, try ecommerce.purchase.products.i.id where i is the index of the object in your array.
If the variable you're trying to access is inside an object (like "revenue" in your example), then you can access it like this:
ecommerce.purchase.actionField.revenue
If the variable you're trying to access is inside an array and your array only contains a single element (like "price" in your example), then you can access it like this:
ecommerce.purchase.products.0.price

How can I send custom dimensions with the product impressions event in Google Analytics?

I am currently trying to send custom dimension values with the product impressions event. Everything else seems to work but I am not able to report on the custom dimension values.
I have set up dimension8 and dimension 9 for star rating and review count. I have passed through these values to the object and it is successfully being sent.
dataLayer.push({
'event': 'productDetailImpressions',
'ecommerce': {
'detail': {
'actionField': {
'list': 'PDP'
},
'products': [{
'name': name,
'id': id,
'price': price,
'brand': brand,
'category': category,
'variant': variant,
'dimension8': reviewCount,
'dimension9': starRating
}]
}
}
});
I have set these custom dimensions up with product scope in GA.
I can view the tag and the information it is sending with a plugin in the browser, the values look correct.
However I am still not able to report on these values inside Google Analytics.
Is there anything I am doing wrong?
Thank you.
The scoping of dimensions required 2 things:
Configure scope in Google Analytics admin interface
See below screenshot:
Send custom dimension with the proper hit
Data is sent to Google Analytics with "hits". Hits are:
page tracking hits
event tracking hits
ecommerce tracking hits social
interaction hits
Now this doesn't mean that you should structure your dataLayer so that the custom dimensions are on the same level ase the object (eg user, product) you're trying to associate them with. Instead, you should follow the standard method for setting dimensions:
In Google Analytics, it is:
// Set the dimension
ga('set', 'cd1', 'Level 1');
// Send custom dimension along with a hit (eg pageview)
ga('send', 'pageview');
Now with Google Tag Manager, GTM doesn't send any hits to Google Analytics, it's just a tool for preparing your data and automating the use of GA. So an example on how to do it:
dataLayer.push({
'event': 'productDetailImpressions',
'dimension8': reviewCount,
'dimension9': starRating,
'ecommerce': {
'detail': {
'actionField': {
'list': 'PDP'
},
'products': [{
'name': name,
'id': id,
'price': price,
'brand': brand,
'category': category,
'variant': variant,
}]
}
}
});
Then create some dataLayer variables to read the custom dimension values:
Finally, assign those dimensions to your GA tags:
note: you could potentially make it work with the dataLayer you have, you would just have to replace your dataLayer variable to point to the right location, however I think it's bad practice because it leads to believe that dimensions have to be nested within the scoped object in order to work (which is not true) and it makes things harder to debug.

Add custom metric to google analytics transaction

Im trying to add custom metrics to transactions on google analytics. It must be per transaction. Currently I'm adding transactions like this.
ga('ecommerce:addTransaction', {
'id': '',
'affiliation': '',
'revenue': '',
'tax': '',
'currency': ''
});
ga('ecommerce:addItem', {
'id': '',
'name': '',
'sku': '',
'category': '',
'price': '',
'currency': '',
'quantity': ''
});
Now what I was thinking was adding the following to the transaction but don't quite know if its the right way to do it.
ga('ecommerce:addProduct', {'metric1': hasTransacted});
I know with page views custom metrics can be added to page view like this
ga('set', 'metric1', '1');
ga('send', 'pageview');
But Im trying to add it to a transaction instead.
Any advice would be greatly appreciated.
You should be able to add the metric to the transaction hit, just like in your example with addProduct. Here is a similar question asked here is it possible to send custom variables to Google analytics while using ecommerce extension.

setting ecommerce values for Google Analytics when using Tag Manager

I just switched over to using Google Tag Manager so everything is mostly in one place. I have to say I love it so far, but I think I have a problem with the analytics ecommerce values.
In Google's documentation they show this as an example as per doc using the dataLayer :
<script>
dataLayer = [{
'transactionId': '1234',
'transactionAffiliation': 'Acme Clothing',
'transactionTotal': 38.26,
'transactionTax': 1.29,
'transactionShipping': 5,
'transactionProducts': [{
'sku': 'DD44',
'name': 'T-Shirt',
'category': 'Apparel',
'price': 11.99,
'quantity': 1
},{
'sku': 'AA1243544',
'name': 'Socks',
'category': 'Apparel',
'price': 9.99,
'quantity': 2
}]
}];
</script>
The above is what I followed. Using Tag Assistant plugin for Chrome shows everything working fine and the values come in as expected, BUT... today I have had a few sales and the data is not showing in my GA account...
I also found this page in the help doc which shows a completely different method for adding the ecommerce data with completely different values. Here they use something like this which is how I was doing it with the regular Google Analytics script (not the tag manager) :
ga('ecommerce:addTransaction', {
'id':'1234',
'affiliation':'some site',
'revenue':100.00,
'currency':'USD'
});
ga('ecommerce:addItem', {
'id': '1234',
'name': 'some product',
'sku': 'some sku',
'price': 150.00,
'quantity': 1
});
So, what is the correct method to specify these values when using the Google Tag Manager?
you are mixing two types of tracking - 1) using GTM and then 2) using the actual JavaScript in source code to send the data to GA.
I would stick with GTM, it just makes everything easier. It seems that you have everything ready in DataLayer with product names, so now you just need to create a new Tag with those attributes:
Tag Type = Google / Universal Analytics
Track Type = Transaction
add any other configuration fields you are using across your website...
Then just create a rule when to fire this tag (usually a conversion page - probably the same as your Goal URL in GA setup).
That should do the trick - if a visitor makes a purchase successfully, then after loading the conversion page, GTM will send 1 pageview reqeust and 1 transaction request (they needs to be fired separately).
Also, you might be interested in new version of E-commerce tracking, named Enhanced Ecommerce. It add tons of new and very useful stuff (apart from measuring transaction, it's focused on the whole process of purchasing - browsing products, adding to carts etc.). Here is the manual how to set it up using GTM. It's a bit more difficult, but worth the effort in my opinion.
Hope this helps.
For anyone interested this is what I came up with for my needs. Works fine, values are just examples of course. Sorry for the late response on this one.
//repeat for each product
myProducts.push({
'name': 'some name',
'id': 'some id',
'price': 100.00,
'category': 'some category',
'brand': 'some brand',
'quantity': 10
});
//full push for the dl
dataLayer.push({
'event': 'TrackOrderComplete',
'google_conversion_value': 100.00,
'google_conversion_currency': 'USD',
'ecommerce': {
'purchase': {
'actionField': {
'id': 'some id',
'affiliation': 'some affiliation',
'revenue': 100.00,
'tax': 5.00,
'shipping': 10.00,
'coupon': 'some coupon'
},
'products': myProducts
}
}
});

Resources