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.
Related
I need to send a cart status update based on an offline activity. My customers will add items to their cart online via the website but the final checkout and purchase happen offline.
Here is my question: In the example below, a checkout step is updated. Does the client_id provided in this step have to match the original client_id used when the web user started their cart originally?
Measuring Checkout Options
v=1 // Version.
&tid=UA-XXXXX-Y // Tracking ID / Property ID.
**&cid=555 // Anonymous Client ID.**
&t=event // Event hit type
&ec=Checkout // Event Category. Required.
&ea=Option // Event Action. Required.
&pa=checkout_option // Product action (checkout_option).
&cos=2 // Checkout step.
&col=FedEx // Checkout step option.
Client ID is how Google Analytics tracks each individual user throughout their multiple sessions. So, yes- if you want that payload to be associated with the same user, then the CID will need to match- otherwise you'll be artificially inflating your user count (as well as severing the contextual data from that user).
You can parse the cookie that GA stores in the browser to obtain the CID and then fill it there. Not sure what language you're writing in, but there are plenty of snippets out there for parsing the GA cookie. You could also store the CID when it is initially generated in your own session data to be used later while offline. For example:
ga(function(tracker) {
var clientId = tracker.get('clientId');
console.log(clientId);
});
You could also provide your own CID from the start that you generate yourself and tell Google Analytics to use. This might be overkill for your situation, but I wanted to mention it as an option.
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.
I'm looking for some general advice. The site I'm currently working on is full of duplicate content that's about to be deduplicated. But it was built that way to track different audiences visiting the pages by reporting on the URL hits.
Current Links
www.MySite.com/homeowner/painting
www.MySite.com/professional/painting
www.MySite.com/designer/painting
My concern is that at the end of the day, the person managing the analytics wants to be able to look at their report and say "We had X number of professionals visit the site." Simply deduping will elimate that.
I'm thinking Google Analytics might have a way to pass audience/tags in via the URL like this:
Example Links with Tracking
www.MySite.com/painting?tag=homeowner
www.MySite.com/painting?tag=professional
www.MySite.com/painting?tag=designer
Is this possible with Google Analytics? Does anyone have an example website using this?
I've looked into Custom Dimensions and Metrics but they seem to be overkill https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets
Custom Dimensions are not overkill, it's a reasonable idea for you to use them (because segmentation is what they are for, really).
Using a url tag has a couple of disadvantages. For one The tagged pages will appear as three distinct rows in your reports - you will be unable to get an aggregated number for www.MySite.com/painting, instead you will have three Urls (or as many as you have parameters).
Secondly, homeowner etc. are attributes that belong to a session, or even a user (if the role cannot change from visit to visit). However if you track them via url parameters they have only a hit level scope, i.e. they are recorded as a property of the viewed page, not the viewing visitor. If you record this as a session scoped variabe you need to set it only at the first pageview, and the value will be applied to all subsequent pageviews for that session.
So an easy way (example assumes you are using php) might be to use
if(isset($_GET['tag']) {
ga('send', 'pageview', {
'dimension1': "<?php echo filter_input(INPUT_GET, 'tag', FILTER_SANITIZE_ENCODED); ?>"
});
} else {
ga('send', 'pageview');
}
in your tracking code after you have created a session scoped custom dimension in your property settings ("dimension1" referring to the first custom dimension in your account, the numeric index changes for each dimension. The dimension name is only used in the reports, not the tracking code). You need to be careful not to send an empty value when the query string is not present - a session scoped custom dimension only records the last value from a session, if you send empty values you overwrite the value you recorded at the first pageview.
Alternatively you can do this without changing the tracking code at all - create a custom advanced filter to capture the value from the query string, a second to copy the value to your custom dimension and a third to remove the query string from the url. However while that's a neat trick using code is much easier.
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)