GA Measurement Protocol: replace custom metric value - google-analytics-api

I have a custom metric in Google Analytics. I'm inserting it using Google Analytics Measurement Protocol.
When I make a request to Google Analytics, is there a way to replace the existing value of the metric instead of adding new value to it?
Let's say that the current value of that metric is cm1=100. When I send the value 500 via Measurement protocol, I want cm1 to equal 500, not 500+100=600. How do I do that?
I'm currently using this kind of URL to insert custom metrics:
https://www.google-analytics.com/collect?v=1&ni=1&tid={tracking_id}&cid={cid}&t=event&ec={category}&ea={action}&el={label}&cm1=500

The Google Analytics Measurement protocol is used for inserting data into Google Analytics, the javascript snipet that websites use also uses the measurement protocol, as does the IOS and Android SDKs.
Once data is inserted into Google Analytics there is no way to change the data that was inserted. For example when you are using ecommerce and a user adds an item to there shopping car the item is inserted into Google Analytics if the user then removes it you need to credit the users record that is done by adding the same item again only with a - value This doesn't remove either item it just nulls them out kind of.
Think of the measurement protocol as inserting a row into a database you insert an event with custom metric 1 having a value of 500 then in 5 minutes you insert another row with custom metric 1 having a value of 200 you now have two rows one where custom metric is 500 and another where its 200. There is no way to update data that has already been inserted into Google Analytics. Google Analytics data does not change once it has been inserted and processing is complete.

No there is not a way to do that. The reason being is that the scope of custom metrics is defined either hit level or product level.
https://support.google.com/analytics/answer/2709828?hl=en

Related

Azure Data Factory: Pagination in Data Flow with Rest API Source

I have a API source in an ADF DataFlow task. The API source gives me the current page and the toatl number of pages in the body of the response. I want to use that information to paginate through my API source. I'm able to paginate through it just fine outside of a DataFlow activity using the range function. The issue is that the Rest transformation in a DataFlow activity does not support the range function. I've been trying to use the AbsoluteUrl function plus an expression to do add one to the current page returned by the body but either pagination does not accept expressions or I cannot figure out the syntax
I have a url like this:
BaseURL/fabricationcodes?facets=relatedArticles:Not%20Empty&page={PageNumber}.
In this example my rest linked service URL has everything I need minus the &page=pageNumber. So I'm trying to add that part with the key/value pair function of AbsoluteUrl. The Key being &page= and the value should be currentPage +1. My desire is for it to get the first page, page 0 and then add +1 to that to formulate the next pages url. the end condition being when body.totalPages == body.currentPage
I've tried a bunch of different expression formaulations but none seem to work and debugging in a Data flow is tough b/c the logging and error messaging is poor
What I have right now.
As data flow don't support Range option or you cannot use dynamic expression to get page from API response.
To work around the issue, you can use Data Flow activity within ForEach loop using range function in dynamic expression.
First take a web activity and pass the URL of the Rest API as below Ito get the total no of Pages from API response
then take a for each activity to iterate on API like pagination give the Dynamic expression as #range(1,activity('Web1').output.total_pages)
I will iterate the API till the respective range in sequential manner.
create parameter with type string in source DataSource.
give that parameter as dynamic value in relative URL.
after this gave parameter value as ?page=#{item()} to give the no coming from range to the page.
OUTPUT:

How to get Height data given during registration from Googlefit REST Apis

I am new to google fit rest APIs and I have been trying to calculate BMI of a user for my project.
So, when the user authorizes to my application at that time I get data for the last 30 days (historical data for some calculation). From then on I extract data periodically this way I always get the latest weight data.
But the issue comes in the scenario when the user has been using google fit way before authentication because I wouldn't know the exact date I should pass as parameter to extract height data.
The aggregate data type accepts the date range of only 90 days, else it returns the error as aggregate duration too large . But the user's height data could be as old as 2/3 years.
I also looked at the option of custom data types, but there again I don't know the exact date range to make an API call.
Is there any way that I can either get the user's joining date (the date he/she registered to Google fit) because a user has to provide height during registration or if I could somehow get data under About you (Gender, DoB, Weight, Height) in Profile tab
Or If I could get the calculated BMI data point directly from API.
Any help would be highly appreciated.

Why do returned data rows from Google Analytics Reporting API include zero values for metrics?

I use the Google Analytics (GA) Reporting API to retrieve custom data from my GA views. Often my queries include a mixture of standard and custom dimensions regarding different URLs and their respective page views, e.g. something like ga:pagePath, ga:pageTitle, ga:dimensionX, where dimensionX is set on a hit level and send with every page view (like publishing date or some CMS identifier).
The returned data regularly includes rows that represent some kind of dimension combination with 0 page views. How can that be? Why would GA report a data point with 0 hits?
PS: I don't use 360, so sampling applies.
Looks like you have set includeEmptyRows: true in the request.
includeEmptyRows boolean
If set to false, the response does not include rows if all the
retrieved metrics are equal to zero. The default is false which will
exclude these rows.
from: https://developers.google.com/analytics/devguides/reporting/core/v4/rest/v4/reports/batchGet#ReportRequest

Google Analytics API TotalEvents query

I'm trying to get a total count for a give event,however I get a number much bigger(10-20 times bigger), than I see on the GA website, what am I doing wrong? (api v3)
here is the segment
metric:
ga:totalEvents
segment:
dynamic::ga:eventCategory==mycategory;ga:eventAction==myaction;ga:eventLabel==mylabel
note that I get wrong results with the query explorer as well.
You are using a segment instead of a filter.
Segments are session based so it will include all events in a session if it matches you specification. So essentially if I triggered the event you want plus other events they will all be included in the total events field.
What you need to do Is remove the segment and add a filter, the filter will include only the data you request.
Hope that helps

Can response data from core reporting api be grouped?

Explanation:
I am able to query the Google Core reporting APIv3 using the client library to get data on pageviews for specific URLs of a website I am working on. I want to get data(pageviews) for each day within a specified range. So far I am simply looping through the range, sending individual request to the API. in each request I am setting the same value for the start date and the end date.
Problem:
Obviously this gets the job done, BUT it is certainly not the best way to go about it. Because, assumming I want to get data for the past 3 months for each of about 2000 URIs. Then I will need 360000 number of requests and that value is well over the limit quota defined by Google.
Potential solution: So one way I thought of solving this issue is probably to send a request setting start-date and end-date to be a week apart but the API will return a sum of the values rather than the individual values.
main question: So is there a way to insist that these values should not be added up and returned as a sum but rather returned (as associative array or something like that) separately for each.
I hope the question is clear and that there is a solution! Thank you!
Very straightforward:
Metric: ga:pageview, Dimension: ga:date, Set a filter for your pagepath, and set a start-date and end-date.
Example:
https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3Axxyyzz&dimensions=ga%3Adate&metrics=ga%3Apageviews&filters=ga%3Apagepath%3D%3D%2Ffaq.html&start-date=2013-06-27&end-date=2013-07-11&max-results=50
This will return the pageviews for that the faq.html& page for each day in the time-frame.
You should check out the QueryExplorer. Great tool to find out how to structure queries.