How to implement Google Analytics Enhanced Ecommerce on server-side? - google-analytics

I'm working on GA in my project. I want to send data about transactions to GA from back-end, and here is a problem. I use "#nuxtjs/google-analytics": "^2.2.0", but it works only from front-end.
Here I have found about Server-side analytics collection, but there where only primitive actions (Event category, Event action, Event label, Event value). As I said, I'm working with Enhanced Ecommerce, so, I need actions like addProduct, addAction and so on.
Is it possible to do such server-side GA?

It's possible to implement using this package.

Related

What is difference between Page Views and Event type in Google Tag Manager and where "some page views" are stored in Google Analytics?

I am kinda new in this topic and wondering what is the difference between Page Views and Event data type in Google Tag Manager. I would like to create an e-commerce funnel. I have configured tags for every steps in GTM and they work properly in preview mode. But I can't find them in Google Analytics. I've been creating tags with pageview -> some page views tags. Where this type of tags are stored in Google Analytics? Should I change it to event data type? And in which case could we need some pageviews tags otherwise?
GTM and GA are two different systems, that unfortunately use the same words for rather different things.
GTM is a deployment system for Javascript tags. In GTM Parlance, an "event" is something that makes GTM update its internal variables and allows for triggering tags. GTM events manifest themselves as a key with the name "event" in the datalayer (GTM overwrites the "push" method of the datalayer array to detect the "event" key when it is contained in an object that is pushed to the datalayer). A pageview in GTM is just one type of event that happens when the GTM code is first executed. By itself it does not send data anywhere and nothing is stored. Data is sent only by the tags that are configured to be triggered by an event.
GA is a system that records tracking data. Tracking data is sent as "hits", where a hit is a http request with a payload that is formatted according to a certain protocol (the measurement protocol, which can be used in any language that supports http requests, and is also used by the analytics.js library). Hits come in different types (pageview, event, timing, and possibly others). The difference is not so much technical (its all http requests), is that the different hit types are by convention tied to different "dimensions", i.e. descriptive properties of the hit. A "page view" hit has a document location and document title. An "event" in GA has additionally the dimensions "event category", "event action" and "event label". That distinction made sense when GA was created, because back then a "page view" was more or less well defined by browser behaviour, but today with ajax and SPAs and all that it becomes more an more meaningless, which is why GA4, the new version of Google Analytics, now only has one hit type - the event, to which you can add dimensions by way of parameters.
So a page view in GTM maybe configured to send a page view in Google Analytics, but does not have to be; the two things have the same name, but exists independently. If a GTM event is not recorded, then it probably has not GA tag connected to it via a trigger. GTM events by themselves do not store data anywhere.
As for the funnel, in Universal Analytics you would create this by implementing enhanced e-commerce. Enhanced E-Commerce can be implemented both via pageviews or via events (that mostly depends on how your page is structured - if you have a checkout with multiple pages you might want to use page views, if everything happens on one page you would rather use events). The important thing is that the appropriate dimensions and metrics are attached to the hit. In GTM the easiest way to this is to have your developers set up the datalayer structure according to the linked documentation, and then you simply check the "enhanced e-commerce" feature in you GA tag and point it to the e-commerce variable in your datalayer (instructions are in the documentation, if you expand the "See the Tag Configuration for this Example" sections by clicking on them).

no data appears on GA Ecommerce report

I need your advice. My developer has implemented the enhanced e-commerce tracker to the website according to this guideline: https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce#measure_purchases
The screenshot below is the screenshot of the data layer that fired when people reached the order completed page.
I'm tracking the order completion via the GTM event tag below:
This event is fired as expected on the order completed page, however, I'm not seeing the transaction data under the GA > eCommerce section after 2 days.
Do I need to advise the developer to implement the tag according to this guideline instead? https://developers.google.com/tag-manager/enhanced-ecommerce#purchases
Is there anything I can do on my end without having the developer to amend the codes on their end?
I appreciate your advice.
Yes, if you're using GTM to pass enhanced ecommerce data you'll need it to be formatted as described in the GTM docs: https://developers.google.com/tag-manager/enhanced-ecommerce#purchases so the pushed object has ecommerce property and subsequently the purchase property.
Your current setup will work with gtag.js implementation but not with GTM Universal Analytics tag.

What is gtag and why do I have to add that separately from google tag manager?

I find Google documentation around Google Tag Manager (GTM) terrible at helping me figure out which bits go where.
As I understand, GTM requires that you put a <script> snippet on your pages which is supposed to bring in other code snippets, as could be configured by a non-technical user.
I'm a technical user, though. Perhaps that's the problem! I also find it problematic that Google use the word "tag" to refer to either an HTML element tag, like <script>, or their own proprietary use of the word to mean calling a function ("triggering a tag") in another script, also unhelpfully referred to as a tag.
They also have "gtag" which is what - a helper? something that enables you to send general analytics events through the GTM API? The docs simply say:
The global site tag (gtag.js) is a JavaScript tagging framework and API that allows you to send event data to Google Analytics, Google Ads, and Google Marketing Platform.
... but we could already send analytics? What does this add?
For example, I wish to send an e-commerce Purchase event.
I've found that to do this I needed to add a new snippet of code with two <script> tags to the header on the site (thought GTM meant I didn't need to do this?) that sources gtag.js, then I'm able to call the following at the appropriate place in my javascript:
gtag('event', 'purchase', { value: 1.23, transaction_id: 'test' });
Or without it (although this does not seem to work):
ga('require', 'ec');
ga('ec:addProduct', {name: 'test product', price: 1.23})
ga('ec:setAction', 'purchase', { id: 'test_id_1', revenue: 1.23 })
So my question is: when would you use gtag() over ga(), and why can't GTM install gtag?
When would you use gtag() over ga()?
Use gtag if you want to send data to supported Google products other than Google Analytics. As you pointed out, "The global site tag (gtag.js) is a JavaScript tagging framework and API that allows you to send event data to Google Analytics, Google Ads, and Google Marketing Platform.", whereas ga only works for Google Analytics. But (see below), you might decide to never use gtag nor ga and always use GTM.
Why can't GTM install gtag?
It could (you could have a GTM tag inserting some gtag code) but it's beside the point as they are meant to be used as 2 different solutions:
gtag is a purely programmatic tracking tool for sending data and only works with 3 Google products (so far - Analytics, Ads, Marketing Platform - more maybe added in the future), it's made to provide basic out-of-the-box tracking with a simple copy/paste + small lines of code (if needed for customization).
GTM is a tag manager: it can work programmatically BUT requires a minimal configuration of the container via the GTM UI (a default container won't send data anywhere), and can send data to whatever products you want (just need to setup the corresponding tags in GTM), while having a bunch of other features
A few questions to help you choose:
Am I sending data to other tools than Google Analytics/Ads/Marketing platform?
Do I want to use some the extra features GTM offers (UI, version control, templates, debug, environments etc...)?
Is there some tracking that would be heavy to implement via pure custom JS (eg scroll tracking) which GTM can facilitate with its built-in listeners (eg scroll tracking)?
If YES to any of the above, then use GTM
I personally never use gtag, I always replace it with GTM because it's considerably more powerful than gtag.
What Google is doing is progressively replacing all their default snippets with gtag so they only have 1 unified API to maintain and it's an easy copy/paste for users (bear in mind most users aren't tech savy and just need to paste the snippets in into their CMS). Forcing people to use GTM would be too much of a friction as out-of-the-box GTM simply doesn't track anything and people would need to learn & configure GTM, too much work vs a simple copy/paste.
Note: The built-in events don't use category, label, and value. Take care to use the correct keys when sending these events.

Google Analytics API For getting total clicks and impression on element

I am really new to Google Analytics and I had a requirement of tracking clicks and impressions. I followed following link
http://www.statstory.com/tracking-clicks-and-impressions-in-google-analytics/
and sucessfully implemented the same.
Now my requirement is to get the no.of clicks and no. of impressions
to my html page. I am googled for past quite hours but couldnot find
any luck with the same.
Any help would be highly appreciated.
You should really consider implementing Google Analytics Enhanced E-commerce functionality.
Google Analytics Enhanced E-commerce
In regards to answering your question of the API, you should query it asking for events. Namely category, action and label events and apply a filter to only return the data you wish to receive, such as 'Impressions' as a filter for 'Event Action'. That will return all impressions and if you instead change the filter to use 'Click', you'd get all clicks instead.
If you followed the above guide and made it into Universal, then you'd see the calls you set and it is set up in the following way:
_gaq.push(['_trackEvent', 'Banner', 'Click', 'BANNERNAME',1.00,true]);
This bit of code pushes (legacy version) Analytics data in the form of:
_gaq.push(['_trackEvent', 'Category', 'Action', 'Label',1.00,true]);
So, changing the different sections means you change how you define the data and how it will be visible in reports. Category defines the Event Category, Action defines the Event Action and Label defines the Event Label.
Take a look at the core development guide. Also, here you can see all the API calls available: Dimension & Metrics explorer for Google Analytics
I gather that you want to track impressions for banner advertising that is displayed by yourself (i.e. not through an adserver) in your website.
I agree with Mr Sponge that you should upgrade to Universal Analytics. if you want to implement enhanced e-commerce tracking (EEC) you probably want to read about Measuring internal Promotions, which is a feature specifically build for that kind of reporting.
If you just need the raw number of banner impressions and/or need a solution that's easier to implement (but less capable) you can increment a custom metric every time you banner shows up (this is basically a counter, you might want to use it together with a custom dimension that holds the banner name). Click tracking would still be done by events (with similar custom metrics and dimensions). From that data you can assemble a custom report and use a calculated metric for click through rates etc.
Not as good as EEC by a fair margin but much easier to do.

Google Analytics scope question

I'm studying GA and and want to know if it is possible to save any custom information. For example I have a lot of checkboxes on the page and want to know checked statistics. I mean checks count for each checkbox separately. I see it in the following way: before postback I'm getting all checks information and send it to GA :).
What do you think?
You can use the Google Analytics javascript API to send this information to google, possibly as an event. This can happen whenever you choose, such as before form submission.
You can make events to each of the checkboxes, individualize them if you want, and see the results in "event tracking" in contents.
More info about event tracking from
google analytics docs

Resources