I am setting up ecommerce tracking for a client and have a few questions to aid my understanding of Google Analytics.
I understand that you have to have an '_addItem' for every product that appears in the receipt. Does this require a change of the JavaScript in any way, or does it use what is already there to generate each item's data automatically?
My other question is: when the JavaScript pulls the transaction and item information from the receipt, do I have to do anything to my website code to make sure that the identifiers used in the JavaScript match the identifiers within the receipt? How does the JavaScript below know what 'total' means in terms of the data it is collecting?
I hope I have made myself clear, please ask if you would like me to elaborate. I'm really just trying to get my head around how this works and what I need to do to get it working.
<script type="text/javascript">
pageTracker._addTrans(
"order-id", // required
"affiliate or store name",
"total",
"tax",
"shipping",
"city",
"state",
"country"
);
pageTracker._addItem(
"order-id", // required
"SKU",
"product name",
"product category",
"unit price", // required
"quantity" //required
);
pageTracker._trackTrans();
</script>
Google Analytics will not autopopulate the reports based on the current page. GA doesn't parse anything on the page. You need to pass all information manually as the parameters to _addTrans and _addItem.
The documentation is very detailed and explains how you should implement it. But in the end the code snippets are just examples. you should generate the code snippets yourself dinamically based on server side logic in order to populate the code with the correct info for that transaction.
Official guide to implement Ecommerce Tracking
Related
Trying to extract a userID from GoogleAnalytics. This is to view which user is the using the website most and least.
I would to retrieve the top 5 user IDs and bottom 5 user IDs that were passed using either:
gtag('config', 'GA_TRACKING_ID', {
'user_id': 'USER_ID'
});
OR
using a custom dimension... ( https://support.google.com/analytics/answer/2709828?hl=en )
I'm (vaguely) aware of policies and TOS to keep 'non identifying' information on Google BUT there are posts online indicating you can link back to CMS data.
Steps so far
Google Analytics with UserID and view setup - Working in Google dashboard and showing filtered userID and All website data using the idea.
Requirements:
Extract page view and session data for each userId between a date
range (or all by default)
UserID via standard GA method
UserID via Custom dimension method
Any help, pointers or examples how someone has completed something like this are appreciated.
NOTE: This is to PULL data out of GA and manipulate/display it on an external system/dashboard.
Seen this which states it's not possible: Google analytics userID tracking
and this which states it (kind of) is google analytics API implementation for tracking a specific user activities in php
The solution I used:
Tracking
Create Google Analytics account
Create a new view by activating the UserID tracking (labeled NewView1)
Use https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets
i.e. Define your custom dimension
Get Analytics tracking code + Add custom definition code
Create a Custom report using the 'metrics' you want to see and filtering by the 'custom dimension' I created earlier.
(note: data took ~ 12 hours to be visible so don't expect to work instantly)
Front end tracking additions
gtag('config', 'GA_TRACKING_ID', {
'custom_map': {'dimension<Index>': 'dimension_name'}
});
// Sends the custom dimension to Google Analytics.
gtag('event', 'any_event_name', {'dimension_name': dimension_value});
Extraction
Create New Google Developer Console Project (API)
Use a Service Account to connect the API with Analytics ( https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-php ) -- API -> credentials -> Create Credentials (Service Account key)
(assign role [mine was set to Project => View])
Save the Text file to your filesystem and rename to json as per examples
Add permissions to your Analytics project by copy/pasting the 'Email' from the Service account details into Analytics User Management.
Get the view ID of the data you wish to extract (Analtyics created in step 2 in tracking)
Use the sample Code (HelloAnalytics.php) to connect and extract data
Use your custom dimension to filter results
The dimension filter I used was $dimensions (see below)
...
$dimensions = new \Google_Service_AnalyticsReporting_Dimension();
$dimensions->setName('ga:dimension1'); // as per docs
// Create the ReportRequest object.
$request = new \Google_Service_AnalyticsReporting_ReportRequest();
$request->setViewId($VIEW_ID);
$request->setDateRanges($dateRange);
$request->setMetrics(array($sessions, $pageviews));
$request->setDimensions($dimensions);
From there I was able to see the same data via API that I could see in the custom report on analytics web.
NOTE: be careful of which Google project and view you're in while setting up
permissions and dimensions.
NOTE: using gtag() code and not Universal (ga()) js code
The answer is a very brief/rough summary of how I achieved my specific goal. It is not a one-size-fits all solution but hopefully it will give someone a better idea of how to set and extract custom variable data within Google.
The final result was data from the API. From there it's up to you.
In the documentation for gtag, there are properties named "list_name" and "list_position" available for products. However, when passing these properties into gtag as described at:
https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce
No list data is sent via the request to /collect. As a result, after switching to gtag, our "Product List Performance" tab in analytics is not showing any meaningful product data. It shows all of our list names, as these are provided by the Impression's "il1nm" parameter. However, "Product List Clicks", "Product Adds To Cart", etc, are all empty.
I've identified that the "pal" parameter is simply not being set on the request to /collect. Even if I straight up copy/paste the example in the docs, the request still does not provide that parameter.
Is this a bug? It is simply unacceptable that this does not work properly, especially with gtag being the recommended integration.
list and list_name does NOT work with gtag implementation.
It is a GA bug:
Google Analytics (gtag.js): Product List Name doesn't appear but other fields do
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.
I am new to funnel setup for virtual Page view. I have an quick question for SEO experts...
As you know, the funnel has "Name " and "Screen/Page".
In following screen, I am wondering about track_Pageview values (e.g: 'inquirey-visitorname-completed'). Are they Funnel's name or "screen/page" values? Please let me know.
Thanks you guys in advance.
in your example(looks like it's example from KissMetrics article) after "onBlur" JS-event happend on example, trackPageview method send virtual pageviews.
In Google Analytics at report "All Pages" you will see values like:
'/inquiry-visitorname-completed',
'/inquiry-country-completed',
'/inquiry-visitorstateprovince-completed',
etc.
In funnel settings you should use, for example, "/inquiry-visitorname-completed" as "Screen/Page".
So, in the "Screen/Page" should be used any type of pageview(real or virtual), like '/thankyou.html', '/order/completed/', etc.
In the "Name" field you can use "Order Lists", "Get a Quote", and so on - this is just name of steps for GA funnels.
I am in the process of setting up enhanced Ecommerce for GA and have had a few requests of additional of what else the client would like to see in their reports. Once of which is
"Where can i see a report if the locations that a use types in when they use the store locator"
There is already an internal search functionality thats been set up and is tracking the search terms people are typing when looking for products, but i'm not sure if i would need to set this up as a second search terms report or if it's something different?
The URL of the page is different to the internal search results and is www.domain.com/store-locator#wales|GB|0|0|0
Any insight into this would be really helpful.
Thanks,
Roxi
As to me knowledge, you are not able to use bookmarks (#something) in GA for internal site search setup. Only GET and POST parameters are allowed. In your situation I think the best solution is to use GA events to send the data about used location each time the user is using this functionality. You need to include addition ga() function call to track those events. Info about how to set it up you could find here: event tracking. After setting things up, you will see all the info about number and type of called events in Behavior -> Events reports section in GA.
Example code:
<button onlick="var hash_location=window.location.hash;ga('send','event','Locator',has_location)">Click me</button>
With such function new event will be send to GA with Event Category=Locator and Event Action=hash in the url. You have some complicated hash, so most probably you need to extract first some info from this using regular expression. Example to get first item from |-separated list in the hash:
var pattern = new RegExp('[^#|]+');
var hash_location = pattern.exec(window.location.hash)[0];