Product-scoped custom dimensions in GA4 - google-analytics

Is it currently possible to add custom dimensions at the product level in GA4, so that they can be used for reporting?
For instance if I send data that looks like this:
event: 'purchase',
value: 500,
items: [
{
item_id: 12345,
item_name: "New Book",
item_author: "John Smith"
}
]
Is there any way to configure GA4 so that I can see the item_author field in product reports? I've seen as late as October 2021 that there is no support for this, but wondered if this had changed, or if Google had published any info as to whether this WILL happen and if so WHEN it will happen?

It is not currently possible. GA4 is still inferior to GA UA in many ways. Product scope dimensions are on the roadmap.
There are a few workarounds we're using like using product categories to store product dimensions. Read this for more: Can I add custom parameters to 'items' in GA4?
//to moderators: please keep this story even if it looks like a duplicate. It gives a good and searchable title to a popular question.

Related

Issue with manual implementation of Enhanced conversions for Google Ads via GTM

I'm having issues with implementation of Enhanced conversions in Google Ads. Would be really appreciative if someone could give me some pointers to the right direction or any suggestion regarding what to try.
The error message I'm receiving is the one below:
"User address data field is incorrectly formatted
Make sure user address is correctly formatted and hashed using the SHA-256 algorithm. See instructions and double-check your setup."
I've been following the instructions specified here: https://support.google.com/google-ads/answer/10172785?hl=en#zippy=%2Cenable-enhanced-conversions-in-google-tag-manager-and-create-custom-javascript-variable
The part regarding "hashed using the SHA-256" appears to be incorrect, since Google in another part of their documentation say that the data shouldn't be se sent hashed, unless you're using the Google API (which is not the case here).
The only value not available in the data layer on the conversion page is "street" so I've left that field out entirely. The other attributes should be present in the data layer.
Which steps have I taken?
Step 1 - Selected "Include user-provided data from your website" in the existing Google Ads pixel/tag.
Step 2 - Configured the variable type "User-provided data" and selected "Code" as type
Step 3 - The data source has the below code:
function () {
return {
"email": {{data.email}} ,
"phone_number": {{Telephone}} ,
"address": {
"first_name": {{First Name}} ,
"last_name": {{Last name}} ,
"city": {{City}} ,
"postal_code": {{zipCode}} ,
"country": {{Country ID}}
}
}
}
Can anyone see if their perhaps is something in the code that's not correct or if their could be any other possible reason why the enhanced conversions aren't collecting data?
Thanks in advance!
I've looked in to using the CSS selector method, but the conversion page only has email data.
Also tried "Manual configuration", but this requires all values to be present, otherwise you can't save (e.g. if "Address" is missing, you can't save)
I've also made test purchases and from what I can see, the conversion tag is picking up the attributes for enhanced conversions correctly.

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.

Google Analytics gtag.js - Ecommerce - Sending product click Event

Decided to use Google's recommended new method of installing Google Analytics: "gtag.js"
I've followed the instructions for measuring "Enhanced Ecommerce" and as part of that build, here's my code to measure a product click:
gtag('event', 'select_content', {
"content_type": "product",
"items": [
{
"id": "TEST-SKU-1",
"name": "Test Product",
"list_name": "Home Page",
"category": "For Testing",
"list_position": 1,
"price": 8.76
}
]
});
I then added that code on the link to the product like this:
<a href="/for-testing/test-product-1" onclick="gtag('event', 'select_content', { 'content_type': 'product', 'items': [{ 'id': 'TEST-SKU-1', 'name': 'Test Product', 'list_name': 'Home Page', 'category': 'For Testing', 'list_position': 1, 'price': 8.76 }] });">
It shows up inside Google Analytics Events (it works), but it shows up with an Event Category/Action/Label of "engagement"/"select_content"/"product". After doing some research, it looks like Google is auto-magically building the Event for me, based off of some new "standard way" they want to do things :-(
QUESTION:
How do I override the gtag.js defaults for Event Category/Action/Label it uses when I send a "Product Click"?
NOTE:
I realize that I can swap out gtag.js for analytics.js or I could use jQuery's post() method and send this directly via Google Analytics' Measurement Protocol but that is NOT my question... I need to figure out "the new correct non-hacky way of doing this"... preferably.
After lots of hacking, inspecting, and painfully time consuming trial & error, I think I got it figured out... One word of caution: This is what I came up with after finding zero info on this subject, so no, I'm NOT 100% certain I've considered everything here. If you know something I don't, please comment below. For those going as insane as I did trying to figure this out, here's what I'm doing:
When you install Google Analytics via the new/default "gtag.js" it actually installs the old "analytics.js" stuff behind the scenes, and it looks like the "gtag.js" is using the "analytics.js" to run code, kinda like a dumbed down wrapper for it.
So what this means is that if you don't like how "gtag.js" is doing something, without editing/hacking/installing/changing anything... all of the old "analytics.js" stuff is available, as long as you remember to do a ga('create'... before the command.
So as a very basic example, here's how you would send a "Test" Event on a link click:
Go Home Test
So that's the answer to my original question: Do it the "old way" because it is the "old way" under the hood anyway.

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.

Setting up ecommerce tracking in Google Analytics

I am setting up ecommerce tracking for a client and have a few questions to aid my understanding of Google Analytics.
I understand that you have to have an '_addItem' for every product that appears in the receipt. Does this require a change of the JavaScript in any way, or does it use what is already there to generate each item's data automatically?
My other question is: when the JavaScript pulls the transaction and item information from the receipt, do I have to do anything to my website code to make sure that the identifiers used in the JavaScript match the identifiers within the receipt? How does the JavaScript below know what 'total' means in terms of the data it is collecting?
I hope I have made myself clear, please ask if you would like me to elaborate. I'm really just trying to get my head around how this works and what I need to do to get it working.
<script type="text/javascript">
pageTracker._addTrans(
"order-id", // required
"affiliate or store name",
"total",
"tax",
"shipping",
"city",
"state",
"country"
);
pageTracker._addItem(
"order-id", // required
"SKU",
"product name",
"product category",
"unit price", // required
"quantity" //required
);
pageTracker._trackTrans();
</script>
Google Analytics will not autopopulate the reports based on the current page. GA doesn't parse anything on the page. You need to pass all information manually as the parameters to _addTrans and _addItem.
The documentation is very detailed and explains how you should implement it. But in the end the code snippets are just examples. you should generate the code snippets yourself dinamically based on server side logic in order to populate the code with the correct info for that transaction.
Official guide to implement Ecommerce Tracking

Resources