Ater googling for an hour or 2 I give up. While executing the code below, this is the result of the Chrome Google Analytics plugin. I have activated Ecommerce in the GA-admin settings for this ID. Pagevies are executed perfectly and visible using ga('send', 'pageview') but a purchase action fails...
analytics_debug.js:10 Initializing Google Analytics.
analytics_debug.js:10 Loading resource for plugin: ec
analytics_debug.js:10 Loading script: "http://www.google-analytics.com/plugins/ua/ec.js"
analytics_debug.js:10 Running command: ga("create", "UA-23554312-1", "auto")
analytics_debug.js:10 Creating new tracker: t0
analytics_debug.js:10 Auto cookieDomain found: "none"
analytics_debug.js:10 Running command: ga("require", "ec")
analytics_debug.js:10 Waiting on require of "ec" to be fulfilled.
analytics_debug.js:10 Registered new plugin: ga(provide, "render", Function)
analytics_debug.js:10 Running command: ga("require", "ec")
analytics_debug.js:10 Waiting on require of "ec" to be fulfilled.
analytics_debug.js:10 Executing Google Analytics commands.
analytics_debug.js:10 Registered new plugin: ga(provide, "ec", Function)
analytics_debug.js:10 Running command: ga("require", "ec")
analytics_debug.js:10 Plugin "ec" intialized on tracker "t0".
analytics_debug.js:10 Running command: ga("ec.setAction", "purchase", {id: "362", affiliation: "Besteld winkel Barendrecht", revenue: "2.95", shipping: "0", tax: "0.17"})
analytics_debug.js:10 Command ignored. Unknown target: undefined
I really do not know what is wrong with this code and it ends with 'unknown target'. Does anybody have a clue what I am missing here?
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-23554312-1', 'auto');
ga('require', 'ec');
ga('ec.setAction', 'purchase', {
'id': '362',
'affiliation': 'Besteld winkel Barendrecht',
'revenue': '2.95',
'shipping': '0',
'tax': '0.17'
});
</script>
Thanx for your time,
Regards, Marc Verkade
This looks like a straightforward syntax error.
Change ec.setAction to ec:setAction and you should be OK.
Related
I have a Firebase account with a project including two apps: android and ios. Recently, I integrated the Firebase project with a Google Analytics 4 account so that I could track in-app events.
I've also configured the Firebase SDK according to the documentation in: https://developers.google.com/analytics/devguides/collection/ga4/ecommerce (my app is e-commerce).
Thera are manny events like:
add_to_cart
purchase
In my Firebase and Analytics account, I'm able to see how many times users have triggered the events, but I'm not able to see the revenue from purchase:
google analytics print
Although I see the monetary value as a parameter, it does not appear as revenue.
My currency is set as "BRL" and the price parameter is a number.
We figured out the problem:
Our code did not include the parameter "value". Although we were collecting "price", without the "value" parameter, Google doesn't recognize revenue.
Exemple code from google:
gtag('event', 'purchase', {
affiliation: 'Google Store',
coupon: 'SUMMER_FUN',
currency: 'USD',
items: [{
item_id: 'SKU_12345',
item_name: 'jeggings',
coupon: 'SUMMER_FUN',
discount: 2.22,
affiliation: 'Google Store',
item_brand: 'Gucci',
item_category: 'pants',
item_variant: 'black',
price: 9.99,
currency: 'USD',
quantity: 1
}, {
item_id: 'SKU_12346',
item_name: 'jeggings',
coupon: 'SUMMER_FUN',
discount: 2.22,
affiliation: 'Google Store',
item_brand: 'Gucci',
item_category: 'pants',
item_variant: 'gray',
price: 9.99,
currency: 'USD',
quantity: 1
}],
transaction_id: 'T_12345',
shipping: 3.33,
value: 21.09,
tax: 2.22
})
I need to populate my database with the User-ID report data for each user (The report I am referring to can be found in Google Analytics > Reports > User Explorer (> click on the user id)).
I am looking at the documentation, but cannot seem to find any dimensions or metrics that I can use to accomplish this: https://ga-dev-tools.appspot.com/dimensions-metrics-explorer/?authuser=1
I wish I had some code examples, however the alternative method would be to run this script (with all the other functions that I will not include in here for simplicity):
def get_user_Activity(analytics, VIEW_ID, user_id, start_date, end_date):
# Use the Analytics Service Object to query the Analytics Reporting API V4.
return analytics.userActivity().search(
body={
"viewId": VIEW_ID,
"user": {
"type": "USER_ID",
"userId": user_id
},
"dateRange": {
"startDate": start_date,
"endDate": end_date
},
"activityTypes": [
"PAGEVIEW", "EVENT"
]
}
).execute()
Which will yield this dictionary for each user-id:
{'sessions': [{'sessionId': '1579xxxx',
'deviceCategory': 'desktop',
'platform': 'Windows',
'dataSource': 'web',
'activiti es': [{'activityTime': '2020-01-22T12:48:20.971410Z',
source': '(direct)',
'medium': '(none)',
'channelGrouping': 'Direct',
'campaign': '(not set)',
'keyword': '(not set)',
'hostname': 'example.com',
'landingPagePath': '/somelandingpage',
'activityType': 'PAGEVIEW',
'customDimension': [{'index': 1}],
'pageview': {'pagePath': '/some/page', 'pageTitle': 'SOME Title'}},
{'activityTime': '2020-01-22T12:48:20.970754Z',
'source': '(direct)',
'medium': '(none)',
'channelGrouping': 'Direct',
'campaign': '(not set)',
'keyword': '(not set)',
'hostname': 'example.com',
'landingPagePath': '/somelandingpage',
'activityType': 'PAGEVIEW',
'customDimension': [{'index': 1}],
'pageview': {'pagePath': '/some/other/path', 'pageTitle': 'SomeTitle'}},...
..................
etc ..............
The trouble of this method is that I would have to go calculate most of the metrics that I am interested in, instead, I would prefer to merely collect the metrics and populate the DB.
If the needed "ga:dimension(s)" and "ga:metric(s)" could please be provided, it would be highly appreciated.
There's no built-in support for userId-level reporting in Google Core Reporting API, so you'll have to calculate all the necessary metrics on your side based on what's available in the Activity API responses.
The only alternative is having a user-level custom dimension with the same value as user ID. However, this only works if you have this tracking implemented in advance.
I have implemented Google Analytics with multiple trackers using this url : https://developers.google.com/analytics/devguides/collection/analyticsjs/creating-trackers#working_with_multiple_trackers
Then have tried to implement enhanced ecommerce in it,But the product categories are not being tracked.In analytics panel , it is showing (not set). I don't know where i went wrong since am not a SEO Expert.
In header :
<script>
//Google Analytics
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-123', 'auto');
ga('create', 'UA-456', 'auto', 'abc');
ga('create', 'UA-789', 'auto', 'xyz');
//Ecommerce tracking code
ga("require", "ec", "ec.js");
//Ecommerce tracking code
</script>
In Product Listing,where all products of same category can be viewed
<script type="text/javascript">
ga('ec:addImpression', {
'id': '<?php echo $sku_idx; ?>', // Product details are provided in an impressionFieldObject.
'name': '<?php echo $curr_product['disp_name'];?>',
'category': '<?php echo check_product_brand($curr_product['category'],$curr_product['L2']).'/'.ucfirst($curr_product['category']);?>',
'brand': '<?php echo $curr_product['style'];?>',
'variant': '<?php echo $attr_code?>',
'list': 'Product Listing',
//'position': 1 // 'position' indicates the product position in the list.
});
At the end
<script type="text/javascript">
ga('send', 'pageview');
ga('abc.send', 'pageview');
ga('xyz.send', 'pageview');
Here is the console :
Initializing Google Analytics.
Loading resource for plugin: ec
Loading script: "https://www.google-analytics.com/plugins/ua/ec.js"
Running command: ga("create", "UA-123", "auto")
Creating new tracker: t0
Auto cookieDomain found: "mytest.com"
Running command: ga("create", "UA-456", "auto", "abc")
Creating new tracker: dieselitaly
Auto cookieDomain found: "mytest.com"
Running command: ga("create", "UA-789", "auto", "xyz")
Creating new tracker: syg
Auto cookieDomain found: "mytest.com"
Running command: ga("require", "ec", "ec.js")
Waiting on require of "ec" to be fulfilled.
Registered new plugin: ga(provide, "render", Function)
Running command: ga("require", "ec", "ec.js")
Waiting on require of "ec" to be fulfilled.
Executing Google Analytics commands.
Running command: ga("require", "ec", "ec.js")
Waiting on require of "ec" to be fulfilled.
Executing Google Analytics commands.
Running command: ga("require", "ec", "ec.js")
Waiting on require of "ec" to be fulfilled.
Executing Google Analytics commands.
Running command: ga("require", "ec", "ec.js")
Waiting on require of "ec" to be fulfilled.
Executing Google Analytics commands.
Running command: ga("require", "ec", "ec.js")
Waiting on require of "ec" to be fulfilled.
Executing Google Analytics commands.
Running command: ga("require", "ec", "ec.js")
Waiting on require of "ec" to be fulfilled.
Executing Google Analytics commands.
Running command: ga("require", "ec", "ec.js")
Waiting on require of "ec" to be fulfilled.
Executing Google Analytics commands.
Registered new plugin: ga(provide, "ec", Function)
Running command: ga("require", "ec", "ec.js")
Plugin "ec" intialized on tracker "t0".
Running command: ga("ec:addImpression", {id: "98263", name: "Ab - Jacket", category: "Apparel/Men/Jackets", brand: "123456", variant: "900", list: "Product Listing"})
Running command: ga("ec:addImpression", {id: "98263", name: "Ab - Jacket", category: "Apparel/Men/Jackets", brand: "123456", variant: "900", list: "Product Listing"})
Executing Google Analytics commands.
Running command: ga("send", "pageview")
Sent beacon:
v=1&_v=j44d&a=1234658035&t=pageview&_s=1&dl=https%3A%2F%2Fmytest.com%2Fproduct%2Fmens%2Fjackets&ul=en-us&de=UTF-/...... some stuff here
_j1 (&jid)
adSenseId (&a) 1234658035
apiVersion (&v) 1
clientId (&cid) 819866210.1464779007
ec:impression list "1" name (&il1nm) Product Listing
ec:impression list "1" product "1" brand (&il1pi1br) 123456
ec:impression list "1" product "1" category (&il1pi1ca) Apparel/Men/Jackets
ec:impression list "1" product "1" id (&il1pi1id) 98263
ec:impression list "1" product "1" name (&il1pi1nm) Ab - Jacket
ec:impression list "1" product "1" variant (&il1pi1va) 900
encoding (&de) UTF-8
flashVersion (&fl) 22.0 r0
hitType (&t) pageview
javaEnabled (&je) 0
language (&ul) en-us
location (&dl) https://mytest.com/product/mens/jackets
screenColors (&sd) 24-bit
screenResolution (&sr) 1366x768
title (&dt) Online Store: jeans, clothing, shoes, bags and watches
trackingId (&tid) UA-123
viewportSize (&vp) 1349x291
Executing Google Analytics commands.
Running command: ga("abc.send", "pageview")
Sent beacon:
v=1&_v=j44d&a=1234658035&t=pageview&_s=1&dl=https%3A%2F%2F Some stuff here
_j1 (&jid)
adSenseId (&a) 1234658035
apiVersion (&v) 1
clientId (&cid) 819866210.1464779007
.
.
.
Executing Google Analytics commands.
Running command: ga("xyz.send", "pageview")
Sent beacon:
v=1&_v=j44d&a=1234658035&t=pageview&_s=1&dl=https%3A%2F%2Fau Again some stuff
_j1 (&jid)
adSenseId (&a) 1234658035
apiVersion (&v) 1
clientId (&cid) 819866210.1464779007
Sorry for pasting such a large console.
I console i can see all the impression data being sent to only one tracking account.Is other 2 tracking accounts getting the data ?
When tracking enhanced ecommerce with multiple trackers, you need to include the tracker name and basically replicate all ecommerce calls for the specific tracker, for example:
ga('require', 'ec', 'ec.js'); // unnamed tracker
ga('abc.require', 'ec', 'ec.js'); // abc tracker
ga('xyz.require', 'ec', 'ec.js'); // xyz tracker
// ...
ga('ec:addImpression', .....); // unnamed tracker
ga('abc.ec:addImpression', ......); // abc tracker
ga('xyz.ec:addImpression', ......); // xyz tracker
// ...
ga('send', 'pageview'); // unnamed tracker
ga('abc.send', 'pageview'); // abc tracker
ga('xyz.send', 'pageview'); // xyz tracker
you have parameter 'Product category', it is wrong
use name 'category'
This is the code being sent from our confirmation page for GA universal using enhanced ecommerce:
ga("create", "UA-XXXXXXX-xx", "auto");
ga("require", "displayfeatures");
ga("require", "ec");
ga("ec:addProduct", {
Id: null,
Name: "ProductNameTest",
Brand: "Foo",
Category: null,
Variant: null,
Price: 5.49,
Quantity: 1,
Coupon: "",
Position: 0
});
ga("ec:setAction", "purchase", {
Id: "33558",
Affiliation: "Foo",
Revenue: 5.49,
Tax: 0,
Shipping: 0,
Coupon: "",
List: null,
Step: 4,
Option: null
});
ga("send", "pageview");
I'm not seeing any issues in the GA debugger or in the Tag Assistant plugin for Chrome.
What am I missing here that our conversion data/transactions aren't showing up?
EDIT:
Here is the output from the GA debugger that I stripped for the above:
Initializing Google Analytics.
Loading resource for plugin: ec
Loading script: "http://www.google-analytics.com/plugins/ua/ec.js"
Running command: ga("create", "UA-XXXXXXX-xx", "auto")
Creating new tracker: t0
Running command: ga("require", "displayfeatures")
Set called on unknown field: "dcLoaded".
Plugin "displayfeatures" intialized on tracker "t0".
Running command: ga("require", "ec")
Waiting on require of "ec" to be fulfilled.
Executing Google Analytics commands.
Registered new plugin: ga(provide, "ec", Function)
Running command: ga("require", "ec")
Plugin "ec" intialized on tracker "t0".
Running command: ga("send", "pageview")
I see a few issues that could be affecting your transactions:
Duplicate ga("require", "ec") commands.
Id for addProduct is null. This is a required value, and should be a string.
More of a javascript best practice: after you've invoked your function, end it with a semicolon. e.g. ga("send", "pageview");
EDIT:
Regarding point #2, the Id for addProduct CAN be null, if the developer is passing a value for the name parameter instead (see Product Data table).
All property key's must be lowercase i.e. Id should be id. (Thanks for Eduardo for pointing out).
When using the multiple tracker support in analytics.js Ecommerce tracking...
https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce#multitracker
Does ecommerce.js have to be required for each tracker?
Like this... ?
ga('require', 'ecommerce', 'ecommerce.js'); // default tracker object
ga('myTracker.require', 'ecommerce', 'ecommerce.js'); // tracker for another web property
Yes, be sure to follow the trackerName.pluginName:method method for the transaction objects.
Here's a bit more information on this from the Google documentation
You can also use the ecommerce plugin if you have implemented multiple
(named) trackers on your page. The plugin works exactly the same as
the default tracker, except that the format is:
trackerName.pluginName:method. For example if you created a tracker
named myTracker:
ga('create', 'UA-XXXX-Y', 'auto', {'name': 'myTracker'}); You would
then load the ecommerce plugin for that named tracker using:
ga('myTracker.require', 'ecommerce', 'ecommerce.js'); The to send a
transaction, you can create a transaction object and pass it to the
named tracker as follows:
var transaction = { 'id': '1234', // Transaction
ID. 'affiliation': 'Acme Clothing', // Affiliation or store name.
'revenue': '11.99', // Grand Total. 'shipping': '5' ,
// Shipping. 'tax': '1.29' // Tax. };
ga('myTracker.ecommerce:addTransaction', transaction); Using this
syntax, the transaction object can be used on multiple trackers.
Finally you would send the transaction data as follows:
ga('myTracker.ecommerce:send');
Here's the link to the documentation https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce#multitracker