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.
Related
Hello Analytics API users!
Is there a Way to get or to filter the totals to get only one type of conversions - e-commerce conversions?
Example from the docs:
mcf:assistedConversions
The number of conversions for which this channel appeared on the conversion path, but was not the final conversion interaction. This metric includes both goal completions and transactions.
All the metrics have both conversion types. Is there a way to get only e-commerce totals? How you deal with this problem?
Yes, it is possible to narrow down your API report to eCommerce transactions.
You need to set up a filter for mcd:converionType to equal Transaction.
An example in PHP would look like this:
$optParams = array('dimensions' => 'mcf:medium',
'filters' => 'mcf:conversionType%3D%3DTransaction');
$ga_result = $analytics->data_mcf->get('ga:'.$profileID,
'2016-08-01',
'2016-08-31,
'mcf:assistedConversions,mcf:lastInteractionConversions',
$optParams);
Further details are available here.
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.
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.
In the Ecommerce Transactions with Google Analytics, we can code as below:
_gaq.push(['_addTrans',
'1234', // order ID
'SitePoint', // store
'19.99', // total
'1.50', // tax
'3.00', // shipping
'Chicago', // city
'Illinois', // state
'USA' // country
]);
But I want to implement it for employer registration page where I wont get order_id and total fields. Instead can I use employer_id and company name by replacing oerder_id and store...
Will it works ?
for reference you can see GA Ecommerce
How to use it for employer registration ?
You can do that but it may not be the best way to do it. If I were going to do it this way I'd use some code to generate a dummy transaction id and then set the total fields to $1. Here is some code to generate an order_id:
function generateOrderId() {
// really crude unique ID
var d = new Date();
var r = Math.floor(Math.random()*1000);
return d.valueOf()+''+r;
}
A better way to do this is to track it with events. These are designed for tracking special things that don't have a dollar amount directly associated. For example, downloads, or the number of times a person clicks play on a video player.
The docs are pretty good and if you understand that Sitepoint article the event tracking won't be hard. (it's actually a simpler process than ecommerce)
https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide
Is it possible to pass more than one label in a single call of _trackEvent(category, action, label, value) so it could be used in report as a separate as a separate dimension or for filtering purposes?
My requirement is to track links (downloads) clicks for documents related with many meta-data parameters (document ID, product ID, category, language, revision etc.) and all those parameters should be available in customized reports.
Thanks in advance for help.
GA is not set up to track that granular of data about any one item.
And, since GA uses gif requests to send the data, you may bump up on the limit given the amount of data you want to send.
One way of tracking all the data you want to would be to push the data into a database via an ajax request.
If you have to use GA for this, you may be able to send multiple _trackEvents for each or a grouping of the meta-data items based on the document. A setTimeout should be used so GA has time to send the events. See Can I track multiple Google Analytics events at once?
In your case you would use:
function recordOutboundLink(link, category, action) {
_gaq.push(['_trackEvent', 'Click', 'Download', 'Whatever']); //could be mutlipush here
setTimeout('document.location = "' + link.href + '"', 100);
}
HTML
<a href="http://www.example.com/pdf.pdf" onClick="recordOutboundLink(this, 'Outbound Links', 'example.com');return false;">
Also, install Chrome and the Google Analytics Debugger. Look in the console (control, shift, j) for the event tracking processing.
If you don't see all of your events tracking there (they will be listed separately), then something is up maybe with the tracking code.
I've found in API docs that the same goal (tracking multiple key-value pairs sent in one _trackEvent request) could be achieved with custom variables:
_gaq.push(['_setCustomVar', 1, 'Items Removed', 'Yes'],
['_trackEvent', 'Shopping', 'Item Removal']);
The one important limitation of this approach is up to 5 maximum number of custom variables (or up to 50 extended custom variables for Premium GA Account)