Google Enhanced Ecommerce, set_checkout_option - google-analytics

I integrated Google Enhanced Ecommerce on a project and integrated calls for the various checkout steps (billing address, shipping address, shipping method and payment method). I'm correctly sending the 'set_checkout_option' event and I set the steps for GA administration, but I still see the steps not populated. Has anyone been in the same situation?
PS: Billing address I think it is always populated because of course it is step 1 and it takes it automatically with the 'begin_checkout' event.

You have to add the checkout_step parameter when calling the checkout_progress event.
gtag('event', 'checkout_progress', {
"checkout_step": 2,
"items": [...]
});
gtag('event', 'set_checkout_option', {
"checkout_step": 2,
"checkout_option": "payment_method",
"value": "paypal"
});

Related

GA4 dimensions like language is (not set) for events sent by the measurment protocol

I am using GA4 measurement protocol to record offline conversions to Google Analytics. I have two conversion events: sale and purchase.
Events are being recorded and in the Monetisation overview I can even see the revenue.
But it seems that GA is not linking these events with other dimensions of the user. For example in any a report breaking down by some dimension of the user, like user's language or OS or other dimensions, I get something lie this:
Note the language code for all sale and purchase events is "(not set)".
But in the user explorer I can see that the sale and purchase events are correctly associated with the client_ids.
How can I make GA4 to associate events through the measurement protocol with the events recorded on the website from gtag for the same client_id?
Example of the payload for a sale event:
{
"client_id": "1799600509.1659478566",
"timestamp_micros": "1659855760249000",
"events": [
{ "name": "sale", "params": { "first_billing": 1 } }
]
}
Example of the payload for a purchase event:
{
"client_id": "1799600509.1659478566",
"timestamp_micros": "1659855760249000",
"non_personalized_ads":false,
"events": [
{
"name": "purchase",
"params": {
"items": [],
"currency": "USD",
"value": 1.2
}
}
]
}
The measurement protocol for ga4 is locked down a lot more then the one for UA was.
Things like language code can not be set via the measurement protocol so will appear as not set.
Until the team decides to open up more for the measurement protocol there's not much that can be done about it other then to use the sdks they supply rather than the measurement protocol directly.
You may want to fill out this and add your voice to the request that they add open up for things.
[Feedback Survey] Measurement Protocol in Google Analytics
It seems like the GA4 MP documentation is off. In addition to the client_id under the root object, you should also add the latest client session_id and session_number params (under the params object of each event).
This should fix the linking of the client device and other dimensions.
Checkout this bug report which shows an example of exactly what you're trying to get.
https://issuetracker.google.com/issues/243678686
I think that Kevin from the google team didn't get the point right and rejected that report.

Tracking Source/Medium with Enhanced Ecommerce event

I have implemented the GA Enhanced Ecommerce in my website, on some event I send this request to GA through JavaScript, like this:
ga('require', 'ec');
ga('ec:addProduct', {
'name': 'Donation',
'category': cookieData.category,
'price': cookieData.revenue,
'quantity': 1
});
ga('ec:setAction', 'purchase', {
'id': cookieData.transactionId,
'affiliation': cookieData.affiliation,
'revenue': cookieData.revenue
});
ga('send', 'pageview');
This part is working without issues, all the data I need is logged where it belongs. Hovewer, on Acquisition > All Traffic > Source/Medium, all Revenue is logged in the (direct) / (none) row, even though most of the traffic comes through the google / cpc source/medium. Consequently, in Acquisition > Google Ads > Campaigns, all Revenues are also at $0.00, even though I can track that much traffic from my Ad Campaigns land on the 'Thank You' page which is seen after the Donation.
When I inspected the data that is sent on this event, I can see that a bunch of other data that is usually sent on the page load is also sent: few different IDs, referrer, etc... So I have no idea if I am doing something wrong, and why the source of traffic that increases the revenue isn't logged properly.
Is there any additional data I have to send together with this set of data? And where to get it?
I know this is a rather peculiar question, and I can't offer any technical explanation, but I managed to work out a solution to my problem.
Instead of using the ga() global object/function, I switched to gtag(), as I found out that by using the ga(), it was like I was creating a blank Google Analytics object with no context. Google Tag object was already filled with all the contextual info I needed, so just by adding a new event with the Enhanced Ecommerce info, it did what I wanted. This is the code I ended up using:
gtag('event', 'purchase', {
"transaction_id": cookieData.transactionId,
"affiliation": cookieData.affiliation,
"value": cookieData.revenue,
"items": [
{
"name": "Donation",
"category": cookieData.category,
"quantity": 1,
"price": cookieData.revenue,
}
]
});
And now it behaves the same regarding the Enhanced Ecommerce info, but is also tracking the source/medium and campaign of all the revenue gathered.

Sending GA E-Commerce Events without Pageview

I'm working on an implementation of Advanced E-Commerce in a "messy" GA/GTM environment with multiple tags and multiple GTM installs.
In order to manage the complexity and prevent multiple page-views from firing for every page, I'm trying to use events to get the data to send to GA, rather than relying on a page-view for that.
For example,
for(var i = 0; i < {{variable}}.length; i++) {
var product = {{wizely.variable}}[i];
ga({{TRACKERID}}+'.ec:addImpression', {
'name': product.name,
'id': product.ID
'list': 'LIST',
'position': i
})
}
ga({{TRACKERID}}+".send","event","Ecommerce","Impressions","LIST",{nonInteraction: true});
This is working great, but I can't seem to find a list of Ecommerce events that GA will accept, and I'm trying to use this method for things other than impressions.
Example, will this work?
ga({{TRACKERID}}+".send","event","Ecommerce","Detail","Detail-Page",{nonInteraction: true});
Thanks!
The ga() method you're using is just regular event tracking, you can name them however. The reason you'd use those is to "send" a hit to GA with the ecommerce data.
There are ecommerce actions that you should consider and THEN send the GA event. See here: https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#measuring-activities

Google Analytics - Some ecommerce transactions are not showing in GA

We have implemented Google Analytics Ecommerce tracking in our web site. We have noted that there are some missing transactions from Google Analytics. Only some data get missing and other transactions are recorded correctly.
There is no specific pattern to those missing orders (e.g. the products that are selected, the device they are using...etc).
Below is the code snippet that push transaction data to analytics.
var products = [];
for (i = 0; i < cart.lines.length; i++) {
var cartItem = cart.lines[i];
if (cartItem != null && cartItem != 'undefined') {
products.push({
'name': cartItem.cartProduct.name + ' ($' + cartItem.cost + ')',
'id': cartItem.cartProduct.id ,
'price': cartItem.cost,
'brand': 'My Brand XXX',
'category': cartItem.category,
'variant': 'My Brand XXX',
'quantity': 1 // Iterating item by item therefore hardcoding quantity to 1
});
}
}
// Pushing ecommerce transaction data to data layer
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'ecommerce': {
'purchase': {
'actionField': {
'id': cart.referenceNumber, // Transaction ID. Required for purchases and refunds.
'affiliation': store.name,
'revenue': cart.totalPrice, // Total transaction value (incl. tax and shipping)
'tax': 0,
'shipping': cart.deliveryCharge,
'coupon': ''
},
'products': products
}
},
'event': 'purchase'
});
}
Note that I have the fully populated 'cart' and 'store' objects accessible.
Appreciate if anyone could help to figure out what's causing this.
Well, Your code seems fine. There isn't any specific way to identify the way what is causing this issue.
You can implement exception tracking in above particular code, by that you will get to know the possible reason which is causing the issue.
To implement exception tracking using GTM you need to wrap up the above code in try catch block and in catch block you push the datalayer event with the exception detail. On other side in GTM configure the exception tracking tag.
Hope this will help you. Let me know in case of any help needed to implement exception tracking.
As Google Analytic is Javascript based platform, there could be a lot of reasons the transaction could be missing, some of the obvious reasons are outlined below -:
Ad blocker is enabled on your browser
JavaScript is disabled
Cookies are turned off
Customer left the page before transaction was sent to Google
Analytics
Payment gateway is not redirecting customers to your order
confirmation page
Order confirmation page may not load for certain payment methods
GDPR extensions can also prevent transactions from reaching Google
Analytics
In the past we have used one of the extensions for our Magento 2 site to sync missing orders between Magento and Google using Measurement Protocol API
Whatever platform you might be using, Measurement Protocol API could be utilised to synch orders between the two system and give you 100% sales data view in Analytics.
If you use a third-party payment processor for some but not all transactions - common example, you accept credit cards on your website but you also accept PayPal payments where the buyer is taken to the PayPal site to complete the transaction - the ones who leave your site to pay are often not counted.
Two reasons: one, many buyers leave straight from PayPal - they never view the order confirmation page where your tracking code is set to send the data to GA.
Two, they're tracked separately because they've technically left your website and then returned, so you need to set up cross-domain tracking to associate them with the correct user session.
(I know this answer is rather late for the OP but thought it might help someone else in a similar situation.)

Using webhooks with Google Analytics

I'm trying to integrate my CRM with Google Analytics to monitor lead changes (from lead to sell) and so on. As I understood, I need to use Google Measurement Protocol, to receive webhooks from CRM and translate it to Analytics Conversions.
But in fact, I don't really understand how to do it. I need to make some script, to translate webhook code to analytics, but where I need to place that script? Are there some templates? And so on.
So, If you know some tutorials/courses/freelancers to help me with intergrating webhooks with Analytics - I need your advice.
Example of webhook from CRM:
{
"leads": {
"status": {
"id": "25399013",
"name": "Lead title",
"old_status_id": "7039101",
"status_id": "142",
"price": "0",
"responsible_user_id": "102525",
"last_modified": "1413554372",
"modified_user_id": "102525",
"created_user_id": "102525",
"date_create": "1413554349",
"account_id": "7039099",
"custom_fields": [
{
"id": "427183",
"name": "Checkbox custom field",
"values": ["1"]
},
{
"id": "427271",
"name": "Date custom field",
"values": ["1412380800"]
},
{
"id": "1069602",
"name": "Checkbox custom field",
"values": ["0"]
},
{
"id": "427661",
"name": "Text custom field",
"values": ["Валера"]
},
{
"id": "1075272",
"name": "Date custom field",
"values": ["1413331200"]
}
]
}
}
}
"Webhook" is a fancy way of saying that your CRM can call a web based service whenever something interesting happens (i.e. the CRM can "hook" into a web based application). E.g. if a new lead is created you can call an url with the lead details as parameters.
Specifics depend on your CRM, but when you set up a webhook there should be a field to set a url; the script that evaluates the CRM data is located at the URL.
You have that big JSON thing as your example - No real way to tell without knowing your system, but I assume that is sent as request body. So in your script you evaluate the request body, extract the parameters you want to send to analytics (be mindful that you are not allowed to store personally identifiable information) and sent it via the measurement protocol as described in the documentation linked in the other answer.
Depending on the system you might even be able to call the measurement protocol without having a custom script in between (after all the measurement protocol is an url with a few parameters).
This is an awfully generic answer, but then the question is really broad.
I've done just this in my line of work.
You need to first decide your data model on how you would like the CRM data to look within Google Analytics. This could be just mapping Google Analytics' event category, event label, event action to your data, or perhpas using custom dimensions and metrics.
Then to make it most useful, you would like to be able to link the CRM activity of a customer to their online activity. You can do this if they login online. In that case, you can set the cid and/or uid of the user to your CRM id.
Then, if you send in a GA hit with the same cid/uid in your Measurement Protocol hit, you will link the online sessions with your offline CRM activity.
To make the actual record hit Google Analytics, you will need to program something that takes the CRM data and turns it into a Measurement Protocol hit, which is essentially just a URL with the correct parameters. Look here for reference: https://developers.google.com/analytics/devguides/collection/protocol/v1/reference
An example could be: http://www.google-analytics.com/collect?v=1&tid=UA-123456-1&cid=5555&t=pageview&dp=%2FpageA
We usually have this as a seperate process, that fires when the CRM data is written to its database (the webhook in your example). If its a lot of data, you should probably implement checks to see if the hit was sucessful, and caching in case the service is not online - you have an optional parameter that gives you 4 hours leeway in sending data.
Hope this gets you at least started.

Resources