Sending GA E-Commerce Events without Pageview - google-analytics

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

Related

Cannot create reports for custom dimensions/metrics GA4

I have implemented a feedback star rating on my website at the bottom of each page. They can select one to five stars and optionally send free-form comments. I have implemented gtag.js to send the star rating integer and comments to my GA4 dashboard. Code snippet is below; I have omitted the JavaScript which allows the user to set the variables, but this is working.
<script async src="https://www.googletagmanager.com/gtag/js?id=MEASUREMENT_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'MEASUREMENT_ID', {
'custom_map': {
'rating_dimension': 'rating_key',
'comments_dimension': 'comments_key'
},
'rating_key': 'this.value',
'comments_key': 'commentsValue',
});
</script>
gtag('event', 'rating_event', {'rating_key': this.value });
gtag('event', 'comments_event', {'comments_key': commentValue });
I went under Configure>Custom definitions and added the dimensions under the Event scope.
The data is being sent as an event, because this is something the user can optionally do on a page. I have verified that the data is sent to GA, I have the Google Chrome GA Debugger, and can see that it is arriving in the Realtime report under Events.
I would like to build a report which shows the page title/URL, the number of views, the length of time spent, along with its average star rating and any comments. I would like to have some adjustable controls so that I can configure this to be shown for a specified length of time. For example, if the page is modified, I can see the average rating before and after the change. Unfortunately, I am not able to build even the most rudimentary view of this data in the new GA web interface. I tried to modify various existing reports to include my custom dimensions, but they don't offer this option. I went under Explore and tried to add a Freeform report, but I can't get the data to show up there either, it only counts the number of times the event has occurred, which is not what I care about at all.
I have gone to a lot of effort to send the data to GA and had expected to be able to access the data and build a basic report.
Is it that you are unable to add custom dimensions and metrics to the free form exploration? Or when you want to add dimensions or metrics, they don't even show up in the custom section?
Normally you have to wait more or less (some say up to) 24 hours before being able to use custom definitions (metrics and dimensions) in any report.
this might not be your case, but I found your post looking for an answer to my problem, which is the custom metrics and dimensions are there, I am just unable to add them to the report, it looks like a bug, I click the + button, check the custom dimensions and nothing happens.

Google Analytics Global Site Tag Custom Parameters

According to Google's gtag.js guide, it seems like we're able to define custom parameters. However, when using the code examples, only the Event Action gets populated. The Event Label is recorded in Google Analytics as "(not set)" and the Event Category as "general".
Code Example from developers.google.com:
gtag('event', 'video_play', {
'video_title': 'My promotional video',
'duration': '01:32'
});
It's also interesting to note that I cannot figure out how to show custom parameters as the columns in Google Analytics seem to be statically set to "Event Category", "Event Action", and "Event Label". These correspond to the default keys of "event_category", "event_action", and "event_label". Using these keys sends the values correctly. The following code works:
gtag('event', 'redirect', {
'event_category': 'Announcements',
'event_label': '/announcements/index.jsp',
Has anyone gotten custom parameters to work or is this a feature that hasn't been implemented yet in gtag.js? Is there additional configuration needed that I may have missed?
If you you were thinking of GA Custom Dimensions and Custom Metrics, yes it is available in the gtag.js / Global Site Tag syntax, see
https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets
in the form of a Map of CD indexes and attribute explicit names, followed by setting values to explicit attribute names.
for example
// Maps 'dimension2' to 'age'.
gtag('config', 'GA_MEASUREMENT_ID', {
'custom_map': {'dimension2': 'age'}
});
// Sends an event that passes 'age' as a parameter.
gtag('event', 'age_dimension', {'age': 55});
See also https://developers.google.com/analytics/devguides/collection/gtagjs/migration#custom_dimensions_and_metrics
However, gtag.js is a wrapper to make analytics.js easier to implement by hiding some its complexity.
If you are used to analytics.js, keep using it, you get more control on its behavior.
Or move to GTM, it's way more flexible.

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.)

How to trigger custom script on Google Analytics event?

I'm using Google Analytics for goal tracking and I need to run a custom script when Goal is complete. Does GA/GTM have any way to solve this? Thanks.
The goal conversion is recorded serverside, so to be nitpicky you cannot track goal conversions on the client. However you can track the pageviews or events that are defined as goals in GA (this is not purely semantical, events and pageviews will happen once per hit, goal conversions happen once per session).
To track if the condition for a goal is met you can use a hit callback, a function that is executed once the tracking call has finished.
<script>
ga('send', 'event', {
'eventCategory': 'Category',
'eventAction': 'Action',
'eventLabel': 'This is set as a goal!',
'hitCallback': function() {
alert("I'm a user function hear me roar!");
}
});
</script>
The alert will be triggered once the event tracking is complete (obviously you would replace the alert with a call to your custom function).

Detect if user is already logged into LinkedIn and log the results

I'd like to track how many people hit my website that might be logged into LinkedIn. Depending on the results, I might add an interactive LinkedIn section using their API.
I already have the Javascript logic to detect if they're logged in. My question is what is the best approach to log this result? Can Google Analytics do it with a custom variable or event detection?
I'd love to report on something like, "10,000 visits to my website, of which X number of visitors were logged into LinkedIn".
Any help would be appreciated!
I believe Google Analytics Custom Tracking Variables would do the trick. Something along the lines of:
_gaq.push(['_setCustomVar',
1, // variable slot
'LinkedInUser', // variable
'true', // value
1 // variable scope, 1=visitor
]);
_gaq.push(['_trackPageview']);
For custom variables (not that is this is a user-triggered event after the initial GA page load logic, a call to _trackPageview is needed to push the data back to GA), or:
_gaq.push(['_trackEvent',
'PageView',
'LinkedIn'
]);
For custom events. Just pop something similar to that into your JS routine that checks for authed LinkedIn users.

Resources