I track the visitor of my web app through google analytics and I'm interested in the "Recency" (found under "Behaviour"). If I log-in to Google Analytics it's easy to download a CSV file with the recency data for a given period of time, but I was wondering if there's a way to get the recency through the Google Analytics API so I can automate the process of generating the reports.
First a suggestion: try out your query in the query explorer to get a sense of what the API is capable of. Currently it uses the V3 API but I would recommend starting a new project with Analytics Reporting API V4.
Answer: Query the API for the dimension ga:sessionCount.
The Analytics Reporting API V4 makes it easy to request ga:sessionCount in the desired buckets. for example I want to see users who have been to the site between 1, 10, 100, 200:
POST https://analyticsreporting.googleapis.com/v4/reports:batchGet
{
"reportRequests":
[
{
"viewId": "XXXX",
"metrics": [
{"expression": "ga:sessions"},
{"expression": "ga:pageviews"}
],
"dimensions": [
{
"name": "ga:sessionCount",
"histogramBuckets": ["1","10","100","200","400"]
}
],
"orderBys": [
{
"fieldName": "ga:sessionCount",
"orderType": "HISTOGRAM_BUCKET"
}
]
}
]
}
Gettings started with the API
Look at the Samples page of the documentation to get an understanding how how the various client libraries frame their requests, and take a stab at one of the quick start guides. Come back here if you get stuck or have a question.
Related
I have tried using Google Analytics Data Api - and issue with it is that the numbers don't much up with what I get from api and from what I see on web ui of Google Analytics. I even tried query explorer for Google Analytics Data Api but got less results again.
From what I am assuming and come to know that google sampling applies on GA Data Api (Although I have results of a day in few hundreds only). Now I heard there is no option to control sampling in GA Data API but there was in GA Reporting API by controlling sampling size option. So I decided to use that. But to my surprise Reporting API only takes View ID and I only had Property ID because I was using GA4 (can't enable universal analytics).
This takes me down to what? I tried Management api and it is for controlling options but not to view data. I tried to import data into Looker and exported from there to myself. But Looker has same results I get from query explorer which are less than web ui of Google Analytics.
I want to do this programatically so just can't use manual export option of GA4.
Need help in finding best way to do it !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
I have done this same thing in google analytics data api, query explorer as well as ga web ui. Ga web ui shows the most results. While query explorer and google analytics data api shows the same after sampling. Attached screenshots for reference.
GA WEB UI _ QUERY
GA WEB UI _ RESULTS EXPORTED TO CSV
QUERY EXPLORER_ QUERY
QUERY EXPLORER_ RESULTS
GA4 DATA API_ RESULTS
EVEN TRIED 3rd PARTY SERVICE Supermetrics GOT SAME
Here is code for GAT DATA API:
`
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
import pandas as pd
from collections import defaultdict
SCOPES = ['https://www.googleapis.com/auth/analytics.readonly']
KEY_FILE_LOCATION = 'MY_GA.json'
property_id = 'properties/266233569'
dimensions = ["date","platform","customEvent:order_id"]
metrics = ['sessions']
request = {
"requests": [
{
"dateRanges": [
{
"startDate": "2022-10-19",
"endDate": "2022-10-19"
}
],
"dimensions": [{'name': name} for name in dimensions],
"metrics": [{'name': name} for name in metrics],
"limit": 10000,
"return_property_quota": True,
"keep_empty_rows": True
}
]
}
credentials = ServiceAccountCredentials.from_json_keyfile_name(KEY_FILE_LOCATION, SCOPES)
analytics = build('analyticsdata', 'v1beta',
credentials=credentials)
response =
analytics.properties().batchRunReports(property=property_id,
body=request).execute()
`
I believe it's a GA4 limitation. If you're considering third-party solutions, Able CDP has its own tracking that connects to BigQuery (so easily accessible in Looker) and provides raw tracking data without sampling.
I am using GA4 measurement protocol to record offline conversions to Google Analytics. I have two conversion events: sale and purchase.
Events are being recorded and in the Monetisation overview I can even see the revenue.
But it seems that GA is not linking these events with other dimensions of the user. For example in any a report breaking down by some dimension of the user, like user's language or OS or other dimensions, I get something lie this:
Note the language code for all sale and purchase events is "(not set)".
But in the user explorer I can see that the sale and purchase events are correctly associated with the client_ids.
How can I make GA4 to associate events through the measurement protocol with the events recorded on the website from gtag for the same client_id?
Example of the payload for a sale event:
{
"client_id": "1799600509.1659478566",
"timestamp_micros": "1659855760249000",
"events": [
{ "name": "sale", "params": { "first_billing": 1 } }
]
}
Example of the payload for a purchase event:
{
"client_id": "1799600509.1659478566",
"timestamp_micros": "1659855760249000",
"non_personalized_ads":false,
"events": [
{
"name": "purchase",
"params": {
"items": [],
"currency": "USD",
"value": 1.2
}
}
]
}
The measurement protocol for ga4 is locked down a lot more then the one for UA was.
Things like language code can not be set via the measurement protocol so will appear as not set.
Until the team decides to open up more for the measurement protocol there's not much that can be done about it other then to use the sdks they supply rather than the measurement protocol directly.
You may want to fill out this and add your voice to the request that they add open up for things.
[Feedback Survey] Measurement Protocol in Google Analytics
It seems like the GA4 MP documentation is off. In addition to the client_id under the root object, you should also add the latest client session_id and session_number params (under the params object of each event).
This should fix the linking of the client device and other dimensions.
Checkout this bug report which shows an example of exactly what you're trying to get.
https://issuetracker.google.com/issues/243678686
I think that Kevin from the google team didn't get the point right and rejected that report.
I am trying to get some information about a specific LinkedIn campaign, but I'm getting an empty 'elements' array as response.
The catch is that the campaign has zero in all metrics when looking on the Campaign Manager. I think it was never actually veiculated, because even the cost is zero (and the status is COMPLETED).
My doubt is: should the array actually be empty, or be filled with zero on the values of the metrics and I'm messing up the requests?
This is what I'm doing:
First a GET request to see all campaigns that are associated with that Token:
GET https://api.linkedin.com/v2/adCampaignsV2?q=search
and this a part of the response:
...
"costType": "CPC",
"name": "Posts",
"offsiteDeliveryEnabled": true
"id": 128237464,
...
Then another GET request to see the info about that campaign:
GET https://api.linkedin.com/v2/adAnalyticsV2?q=analytics&pivot=CAMPAIGN&dateRange.start.day=25&dateRange.start.month=6&dateRange.start.year=2019&timeGranularity=MONTHLY&campaigns[0]=urn:li:sponsoredCampaign:128237464
But this is the response:
{
"elements": [],
"paging": {
"count": 10,
"start": 0,
"links": []
}
}
My app has the r_ads_reporting permission and Development tier on the Marketing Developer Platform.
I've also manually added the account ID of that company on the MDP Settings.
The problem was in the campaigns I used. After this I tested with some campaigns that had real ads and I got the expected response
Hi I am trying Google Cloud Vision , to detect character and words in Arabic language from image. But when i try it gives me result in matching them with english:
Request code is as below:
{
"requests": [
{
"features": [
{
"type": "TEXT_DETECTION"
}
],
"image": {
"source": {
"imageUri": "gs://dummy/noon-1.png"
}
},
"imageContext": {
"languageHints": [
"ar"
]
}
}
]
}
The Vision API service use machine learning models that are being trained constantly in order to improve the results quality; however, sometimes they get the characters wrong or even they don't recognize the characters themselves
Based on this, I suggest you take a look on the Supported Images document where you can find some file format and image sizing recommendations that may help you to improve your results accuracy, as well use the Send Feedback button, located at the lower left and upper right corners of the Vision API public documentation, or use the Issue Tracker tool in order to raise a Vision API request and notify to Google about this behavior.
I'm trying to integrate my CRM with Google Analytics to monitor lead changes (from lead to sell) and so on. As I understood, I need to use Google Measurement Protocol, to receive webhooks from CRM and translate it to Analytics Conversions.
But in fact, I don't really understand how to do it. I need to make some script, to translate webhook code to analytics, but where I need to place that script? Are there some templates? And so on.
So, If you know some tutorials/courses/freelancers to help me with intergrating webhooks with Analytics - I need your advice.
Example of webhook from CRM:
{
"leads": {
"status": {
"id": "25399013",
"name": "Lead title",
"old_status_id": "7039101",
"status_id": "142",
"price": "0",
"responsible_user_id": "102525",
"last_modified": "1413554372",
"modified_user_id": "102525",
"created_user_id": "102525",
"date_create": "1413554349",
"account_id": "7039099",
"custom_fields": [
{
"id": "427183",
"name": "Checkbox custom field",
"values": ["1"]
},
{
"id": "427271",
"name": "Date custom field",
"values": ["1412380800"]
},
{
"id": "1069602",
"name": "Checkbox custom field",
"values": ["0"]
},
{
"id": "427661",
"name": "Text custom field",
"values": ["Валера"]
},
{
"id": "1075272",
"name": "Date custom field",
"values": ["1413331200"]
}
]
}
}
}
"Webhook" is a fancy way of saying that your CRM can call a web based service whenever something interesting happens (i.e. the CRM can "hook" into a web based application). E.g. if a new lead is created you can call an url with the lead details as parameters.
Specifics depend on your CRM, but when you set up a webhook there should be a field to set a url; the script that evaluates the CRM data is located at the URL.
You have that big JSON thing as your example - No real way to tell without knowing your system, but I assume that is sent as request body. So in your script you evaluate the request body, extract the parameters you want to send to analytics (be mindful that you are not allowed to store personally identifiable information) and sent it via the measurement protocol as described in the documentation linked in the other answer.
Depending on the system you might even be able to call the measurement protocol without having a custom script in between (after all the measurement protocol is an url with a few parameters).
This is an awfully generic answer, but then the question is really broad.
I've done just this in my line of work.
You need to first decide your data model on how you would like the CRM data to look within Google Analytics. This could be just mapping Google Analytics' event category, event label, event action to your data, or perhpas using custom dimensions and metrics.
Then to make it most useful, you would like to be able to link the CRM activity of a customer to their online activity. You can do this if they login online. In that case, you can set the cid and/or uid of the user to your CRM id.
Then, if you send in a GA hit with the same cid/uid in your Measurement Protocol hit, you will link the online sessions with your offline CRM activity.
To make the actual record hit Google Analytics, you will need to program something that takes the CRM data and turns it into a Measurement Protocol hit, which is essentially just a URL with the correct parameters. Look here for reference: https://developers.google.com/analytics/devguides/collection/protocol/v1/reference
An example could be: http://www.google-analytics.com/collect?v=1&tid=UA-123456-1&cid=5555&t=pageview&dp=%2FpageA
We usually have this as a seperate process, that fires when the CRM data is written to its database (the webhook in your example). If its a lot of data, you should probably implement checks to see if the hit was sucessful, and caching in case the service is not online - you have an optional parameter that gives you 4 hours leeway in sending data.
Hope this gets you at least started.