Can you update items in a transaction in enhanced analytics? - google-analytics

I am using the enhanced ecommerce plugin for Google Analytics in my store.
I am using analytics.js to send transaction information in the checkout success page.
After completing the transaction, I want to update some custom metrics associated with products in the transaction which are not available in the checkout success page.
I was wondering if it is possible to do this via the measurement protocol and if so how?
Thanks

It is not possible to update data that has already been sent to Google Analytics.
The measurement protocol works exactly as analytics.js does as a matter of fact analytics.js uses the measurement protocol. It is only used to send information to Google analytics.

You can ad custom dimensions via the data import feature (https://support.google.com/analytics/answer/6014867?hl=en), and even that is applied to incoming data (not retroactively) but I am not aware of a way to import metrics. You certainly cannot do it via the measurment protocol, since this only records new interactions, it does not change existing ones.
The only thing that I know that changes existing data is doing refunds, but I think about the only metric you can change with that is transaction totals.

My answer is a year old, but i think i should update an answer. Updating item is possible, but there would a side effect to it. If you call your script again, this will update the transaction in google enhanced eCommerce. For e.g if a customer has purchased a red shirt from your e-commerce site, and the customer called you that he want green shirt also, you add green shirt to his item to the customer order from the admin control panel side, now you want to update the google analytics, do following code.
ga("create", "UA-XXXXX-Y");
ga("require", "ec");
ga("ec:addProduct", {
"id": "bc823",
"name": "Fuelworks T-Shirt",
"price": "92.00",
"brand": "Fuelworks",
"category": "T-Shirts",
"variant": "green",
"dimension1": "M",
"position": 0,
"quantity": 1
});
ga("ec:setAction", "purchase", {
"id": "d811e9a6-82d5-4145-8f59-9f040cc18fdd", // keep this same to the customer order id.
"affiliation": "Online Store",
"revenue": 194, //calculate net total revenue i.e. only new product added revenue
"tax": 0,//calculate net total tax i.e. only new product added tax
"shipping": 5 // //calculate net total shipping i.e. only new product added shipping
});
ga("send", "pageview")
$194 revenue will be added to your google eCommerce transaction. $5 shipping cost will be added in your google eCommerce transaction.
Now lets talk about side effect, if you update your transaction a day
after the original transaction date, google will also update your
transaction date. Google enhanced e-commerce script does not support
any purchase date parameter, which they should.

Related

Send custom data to google analytics from server side

I want to send these information title, target amount, category, account name to GA for every user who creates a page in our website. And if anyone make transaction on that page I want to generate a revenue of 5% based on the transaction amount for every transaction. I've no clue how to do that.
So far what I've achieved is I set up the service account by following this link and create a custom dimension. Playing with the code snippet I can update the name of the dimension and other things but not sure how to send an object value with all the fields that I need in this custom dimension. My question is if I call this again will it update and replace the old value with the new value? I don't want that. Every time I want to insert a new value in the old value. Shall I need another dimension and what if I want to relate this custom dimension data to ecommerce later on. How can I do that?
try:
analytics.management().customDimensions().update(
accountId='123456',
webPropertyId='UA-123456-1',
customDimensionId='ga:dimension2',
body={
'name': 'Campaign Group',
'scope': 'SESSION',
'active': True
}
).execute()
Can someone please suggest me what should I do here.
you use the measurement protocol to send data to google analytics. The google analytics management api is only for managing your google analytics account.
POST /collect HTTP/1.1
Host: www.google-analytics.com
payload_data
This article should help you achieve what you want.
Basically the custom dimensions in your url should be like cd1, cd2 so on...
https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters?hl=en#customs
Here is a code sample that might help
https://www.simoahava.com/analytics/13-useful-custom-dimensions-for-google-analytics/#23-payload-length

Sending a custom dimension to Google Analytics using the Google Measurement Protocol

I am currently trying to send a hit to Google Analytics from my CRM. I have been successful in sending events and purchase as well as products etc. However, when I try to send through a custom dimension I am not seeing this dimension within the user explorer section of Google Analytics.
My example case as follows:
I go to the Google Analytics Hit builder to build a prototype hit for this interaction found here
I send through an event to Analytics as follows; this contains the all important custom dimension:
v = 1
t = event
tid = {{Analytics account ID}}
cid = {{Random string}}
ec = Offline sales
ea = Completed sale
el = Oflline sale completed
ni = 1
cd4 = Sale made
(Don't run the above, you need to enter it into the respective fields in the hit builder)
I validate this hit and as you can see below it will show valid and will send
Image of valid hit
The event shows up in the real time events
However, the custom dimension never shows up in Analytic's user explorer
Could someone please assist?
Since you specifically mention the user explorer report my educated guess would be that your custom dimension is not user scope (which is the only scope the user explorer will show).
Look if you can select them as secondary dimension in your standard reports or build a custom report (or rather more straightforward, check the scope of your dimension in the property settings)

Google Tag Manager: cart persistency

in Google Tag Manager and Google Analytics, I am trying to track cart addition so that I can then compare them with effective purchases and see which product I am losing most of my business for.
Till here, I am fine. I set up the following data layer with a product array.
for (var i=0; i < myvariable.length; i++) {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push ({
'event': 'AddtoCart',
'ecommerce': {
'currencyCode': myvariable[i]['currency'],
'add': {
'products': [{
'name': myvariable[i]['name'],
'id': myvariable[i]['id'],
'category': myvariable[i]['category'],
'price': myvariable[i]['price'],
'variant': myvariable['variant'],
'dimension1': myvariable[i]['mydimension'],
'quantity': 1,
}]
}
}
});
}
Now, I need to persist data layer throughout the different ecommerce steps in order not to duplicate the values every time user goes ahead or even jump backwards. And here is the problem, based on the structure of the ecommerce I work with:
Page 1: product list
Page 2 (optional, depending on the settings): product upgrades
Page 3: Guest details
Page 4: Confirmation
In page 1 when a user selects a product he jumps directly to page 2 (if present) or 3. If he wants to select another product he has to go back and select again. All products are stored in the cart, which is generated as soon as the user adds a product, regardless of page the user is.
What I would like to have is to track all product listed in the cart before he either closes the page/jumps out of the purchase process or confirms the purchase. It doesn´t really matter what he adds, removes, re-adds during the purchase process. Basically the last cart status (with all products listed) is what I want to be sent to Google Analytics as an event.
I understand this is something I can achive with cookies, but not sure how exactly I should set it up, store all data in it and then trigger it to GA. I would really appreciate a few hints in this matter.
Thanks in advance for your help.
Here is how you can setup a cookie
How do I create and read a value from cookie?
You will setup the cookie with any value you'd like
GTM can read cookies
https://support.google.com/tagmanager/answer/6106899?hl=en#web
http://www.simoahava.com/analytics/variable-guide-google-tag-manager/#1
you would need to create a variable with 1st party cookie and enter the name of your cookie
and then add filter to your trigger to fire when variable does not matches your value
Hope this help,
Cheers Analytics ML.

How to Track Profit in Google Analytics?

I have Google's standard ecommerce script implemented in the purchase page of a web site I admin. The standard script allows the revenue to be tracked, but it doesn't have a default data type to track the profit of each purchase.
I didn't know how to add a custom data type into the ecommerce script or how to handle its processing in Analytics, so I spent quite a while today and have learned a bit. However, I still have some questions...
My current ecommerce script is something like this (please note that I've left the value for each data type blank, just for demo purposes):
<script type="text/javascript">
ga('require', 'ecommerce');
ga('ecommerce:addTransaction', {
'id': '',
'affiliation': '',
'revenue': '',
'shipping': '',
'tax': ''
});
ga('ecommerce:addItem',
{
'id': '',
'name': '',
'sku': '',
'category': '',
'price': '',
'quantity': ''
});
ga('ecommerce:send');
</script>
I know that I should create a custom metric (since profit is an integer), but I'm not sure if the scope I select should be product-level or hit-level. I was thinking product-level because each product can have a different profit amount. Am I correct?
If yes, does that mean I should migrate over to the enhanced ecommerce code? (as I think that the product-level tracking is only supposed by the enhanced version, right?)
Does it even matter which scope type I select if each transaction only has a single product?
I have other questions, as far as how to implement the code for the metric in the tracking, and how to view the tracked data in Analytics (hopefully within one of the standard ecommerce views), but the questions about the scope and code version are the first steps to get this set up correctly.
Thanks!
You can't include custom metrics or dimensions with standard ecommerce, so you should switch to enhanced ecommerce, where you can include product-scoped metrics and dimensions quite easily.
Enhanced ecommerce offers much more flexibility in terms of the reports that are available (shopping behaviour, checkout behaviour, product list performances, sales, checkout funnel, etc.) and also gives you the ability to track custom data points through custom dimensions and custom metrics that wouldn't be available with standard tracking.

add transaction manually to Google Analytics and eCommerce

I'm using the following tutorial, http://www.lunametrics.com/blog/2014/03/04/tracking-offline-transactions-universal-analytics/ which tells us how to add a transaction manually using a url like the following:
http://www.google-analytics.com/collect?v=1&tid=UA-123456789-1&cid=75839030.509493873&t=transaction&ti=52ea5aab1f0c2&tr=1100&cd1=52ea5a8bc6a4a
This works ok. However, the eCommerce part of GA does not register a conversion, so it's not possible to use the multi channel funnels report.
I'm wondering is there a way to register a sale similar to how a shopping cart would on a webpage? Would I have to add in the "clientId" for the customer, into the cart so the sale can be recorded against all the other actions in GA?
OR am I doing something wrong? Such as not registering an item? Would this trigger the ecommerce conversion to register?
Either way, somehow the ecommerce tag is not firing, so I can't record multi channel funnels based on clientId
You need save clientId in custom dimensions and in your site (it can be hide field, for example)
If you send transaction with use real clientid (send cid and cd# parameters) = this transaction will be linked with this user and all actions with this cid
On my practice better send t=event&ec=ecommerce&ea=purchase&pa=purchse&item...
With this method I have all data in ecommerce reports

Resources