Google Analytics Measurement protocol batch request not working properly - google-analytics

I am trying to send multiple hits in a single request to Google Analytics !
Sometimes it sends one or two hits, sometimes it doesn't send at all !
I have tried to do the same thing, placing \n after each hit in my request https://www.google-analytics.com/batch?v=1&t=event&tid=UA-XXXXX-1&cid=555&ec=video&ea=play&el=holiday&ev=300\nv=1&t=event&tid=UA-XXXXXX-1&cid=555&ec=test&ea=test&el=test&ev=test
But still, sometimes it sends one or two hits, sometimes it doesn't send anything !
Please, help me to deal with this issue !

It looks like you are using wrong ev values, event value cannot be string it can only be integers. And you are passing ev = test for 2 entries. Check This
For more details on the GA parameters and its value check this

Try to send with a little delay between the individual hits or add more parameters like location and screen resolution.

Related

Google Analytics 4 measurement protocol not working

I tried to send event to Google Analytics 4 using the postman.
And GA4 just response 204 No Content and the event is not recorded in the data stream.
I checked the measurement_id and api_secret has right value.
Is there anything wrong?
Thank you.
I encountered this issue today.
For me personally, it turns out I was looking for my received data in the wrong place: I was looking in Admin > Data Streams, which incorrectly told me "No data received in past 48 hours."
Where I actually needed to look was in the "Realtime Overview" (Reports > Realtime - see picture):
In there, there was a handy little event counter that showed me my events were, in fact, getting through just fine.
If you check here and it's still zero, here are some other things to try:
You may need to set the Content-Type header to "application/json".
Validate your events by sending them to the endpoint https://www.google-analytics.com/**debug**/mp/collect rather than https://www.google-analytics.com/**debug**/mp/collect - as long as you get "validationMessages": [] back, you should be good to go.
Make sure the JSON you're sending matches this format
According to the folks over at this similar StackOverflow question, You may need to set the User-Agent header, though I personally did not have to.
The object should be payload, not body.
Try to see this video: https://youtu.be/WSxdrG1G_yE

Google Analytics data limits

We are using Google Analytics on a webshop. Recently we have added enhanced ecommerce to measure more events so we can optimize the webshop. But now we are experiencing less pageviews and other data is missing.
I don't know what it is, but on a specific page we are nog measuring anymore, I removed some items from the ga:addImpression data, and now the pageview is measured again.
I can find limits for GA, but I can't find anything for the amount of data that can be send to GA. Because is this seems to be related to the amount of data that is send to GA. If I shorten the name of a product, the pageview is also measured again. GA is practically broken now for us because we are missing huge numbers of pageviews.
Where can I find these limits, or how will I ever know when I'm running into these limits?
In one hand, im not sure how are you building your hits but maybe you should keep in mind the payload limits to send information to GA. (The limit is 8Kb)
In the other hand there is a limit in fact that you should consider (Docs)
This applies to analytics.js, Android iOS SDK, and the Measurement Protocol.
200,000 hits per user per day
500 hits per session
If you go over either of these limits, additional hits will not be processed for that session / day, respectively. These limits apply to Analytics 360 as well.
My best advise is to regulate the amount of events you send really considering which information has value. No doubt EE data is really important so you should partition productImpression hits in multiple ones of the problem is the size. (As shown in the screenshot)
And finally, migrate to GTM.
EDIT: Steps to see what the dataLayer has in it (in a given moment)
A Google Analytics request can send max about 8KB of data:
POST:
payload_data – The BODY of the post request. The body must include
exactly 1 URI encoded payload and must be no longer than 8192 bytes.
URL Endpoint
The length of the entire encoded URL must be no longer than 8000
Bytes.
If your hit exceeds that limit (happens e.g. with large product lists in EEC tracking) it is not (as far as I can tell) processed.
There are also restrictions to field length for some fields (e.g. custom dimension with max 150 bytes, others are detailed in the parameter reference ).
In some cases the data type is relevant, e.g. if in your event tracking the event value is set to a string the call might fail.
I think this is the page you are looking for Quota and limits page can help
These limits apply to the Web Property / Property / Tracking ID.
10 million hits per month per property
If you go over this limit, the Google Analytics team might contact you and ask you upgrade to Analytics 360 or implement client sampling to reduce the amount of data being sent to Google Analytics.

Google Analytics: How to overcome payload size restriction?

I use Google Analytics Enhanced E-commerce for some shops. On catalog page I have many products and I need to track their impressions. I do not track each product one-by-one, cause it will cause many requests, instead I add all of them through .ec:addImpression and then track entire pack by sending single pageview.
And everything was going well until I faced a problem, that on page with too many products requests to collect stopped working with no error. I've installed analytics debugger for Chrome and found out, that I've exceeded a payload limit, which is set to 8 KB (according to official documentation):
payload_data – The BODY of the post request. The body must include
exactly 1 URI encoded payload and must be no longer than 8192 bytes.
And this is fine, but here's my question: is there any way to overcome this restriction? Maybe some option or method, that will allow not to bother about payload size and it will be automatically split into proper chunks? Or at least a method to get a payload in run-time to check its size. I run through documentation and found nothing.
Note: currently I manually track a "safe" number (which was discovered by experience) of products added by addImpression and then send them by non-interaction pageview hit. Of course, this solves my problem, by I want to know if there's a built-in solution.
Another possibility is to send only true impressions, that is, only for those products/items that the user is actually seeing above the fold. Not all products that you are sending impressions for are actually seen by the user until they scroll down the page below the fold. So this would require a modification to the implementation where you send your impression data as the user scrolls down the page and reveals more products. You can likely send more information with each product and still not exceed the payload, and you get a more accurate measure of your impressions.
Create a product data import that matches your product ids to product to product attributes (name, category, price etc). Wait until the data is processed, then change your tracking code so that only product ids are sent.
That should shrink down the request body enough to send all products, and the ids will be joined with the imported data when the incoming hits are processed.
Imported data is not applied retroactively, so it'S important that you do the data import first.
AFAIK there is no way to get your payload size from google analytics and it's a crying shame that analytics.js does not handle this issue automatically since the analytics.js library which constructs the payloads is best suited to handle this and thus minimise load on Google's servers...
I like Eike's solution, though if your products change a lot it might require automation. As #nyuen implies - sending only real impressions may help and is more accurate.
Another trick is to send the impression one at a time. (As shown or on page load) This will require the smallest change and reduce the payload to well bellow the limit.

How to get only CHANGED data from Google Analytics API?

I'm using Google Analytics API to get the number of page views for each page of my website. In order to reduce the number of api calls, I'm setting an interval for doing this and cache the data on my server. For each api call, I try to get the page views of every page on my site and update them to my database.
Is there a way to get only CHANGED DATA from a specific time stamp? For example, only page views that changed within last 2 hours.
I think it would be a kind of filters (if any) but I could not find it from the documentation here https://developers.google.com/analytics/devguides/reporting/core/v3/reference#filters
You could add a filter for ga:dateHour so that it comes back in the last two hours. But the problem is that it takes Google around 4 hours to process the data. So you wouldn't get anything back for two hours ago.
If you want to see data that is that new you have to use the Realtime api https://developers.google.com/analytics/devguides/reporting/realtime/v3/
What exactly is your query currently? If you do ga:date, ga:dateHour, ga:pagepath, ga:pageviews The results will all be returned in one query (not counting next pages), thats a log way to the 10,000 queries per day limit.
On a side note. What do you mean by changed? Nothing is going to change in data previously processed.

Request GA statistic data for a specific large set of pages

I've spent last few days trying to find a solution to solve problem below.
I have set of URLs for which I would like to request data - mainly pageviews and visits by months in specific time interval. These URL specify one web section and we would like to get statistics for this section. I'm using PHP GAPI.
I am able to construct correct filter for the URL set:
ga:pagePath==[url1]||ga:pagePath==[url2]||ga:pagePath==[url3]...
But this works for a fews URLs because request is sent via GET and there is request length limitation for GET.
At first I tried to make severeal requests for a few URLs from the whole set and after all requests (when I had data for all pages) I made sum of pageviews and visits. Than I realized that this could work for pageviews but not for visits (one particular visit could be counted in more than one response and thanks to sum it was counted muliple times).
And than i have these limitations:
I can't use regular expresion to shorten the filter. URLs of pages are badly designed (not thanks to us :) ) and the pages in a web section therefore don't have nice URL prefix like /my-section/*
I need historical data (2 years back), so it won't help to start tracking some custom variable or event for pages in particular web section from now.
So I tried to make POST request to API. I was able to get auth token, but POSTing request to get statistic data returns:
403 Forbidden
Target feed is read-only
I tried to find if there is actualy the possibility to use POST method, but had no luck finding exact info (some clues suggest that it is not possible).
Another idea could be redesigning URL to have some nice prefix to filter by regexp and somehow changing the stored URLs in GA, but I have a feeling that it's not possible either.
Does anyone have an idea how to solve this?
Thanks for any suggests :)

Resources