Creating a report with GA4 data API and using segments - google-analytics-api

I understand that GA4 data API does not support segments yet. I read that you can imitate a segment using audiences. In my code, I create a new dimension 'audienceName', however, it only returns 'All users' audience. How can I select the audience I manually created in GA4 UI with the criterias needed for my query to show me the data I want ?
Thanks!

Related

Custom GA data costs = Analytics API column missing?

I am trying to use custom cost data (from PLA, price comparison sites), I already upload data on daily basis, it shows up in GA. However, It does not work as expected on API side - as I need to use this cost data for custom reporting, using ga:adCost return cost data only for Google Ads, nothing else. As I have checked, there is no other cost column in dimensions or metrics....
Concrete:
I import cost data using APIs
Success
However, on the API side, when I want to use that data as a source for data export, the only ,,cost,, related colum is adCost - but only Google Ads costs as a traffic source are returned
https://ga-dev-tools.appspot.com/dimensions-metrics-explorer/
I would expect all traffic sources to have ga:adCost (or ga:cost?) in API as well, however, only Google Ads have that. I suppose that ga:ad* is related to GAds connection data only and custom data imported are to passed to Analytics API and/or there is no metric for that data...
Am i doing wrong API calls to get traffic source / medium & cost data, or custom imported data are not able to get back via API?
Is there a solution? Thanks!

How to get sample data from sales force developer account through rest api

I need to get sample data from sales force developer account but i am unable to find any API to get any data from sales force.
Is there any API exposed by sales force to accomplish the task.
Salesforce exposes a large number of thoroughly documented APIs.
Access to record data is most commonly achieved through the standard REST API.
You may be most interested in the endpoints named under Working with Records, which provide access to record data, or Working with Searches and Queries.

How to get around salesforce API limit

I am building a chrome extension/third-party app that needs to read data from salesforce.
One way is to make a API call directly to salesforce whenever a user needs to query something, but this will create a large number of API calls.
What I attempted to do is to pull a ton of data from salesforce into a Google Sheet using the reports API, on an hourly basis, then query the data through Google App Script. But Salesforce's 2000 row limits for Reports and SOQL API, as well as the runtime limits posed by Google App Script, make my life difficult :(
What are the best ways to get data from salesforce for third party extensions?
Appreciate your help!
The bulk API can fulfill your needs as it hasn't a limitation on the number of returned rows.

Google Analytics API - retrieve Custom Segment Id by its name

Using Google Analytics API to retrieve 20+ Profiles' data so i can combine all of them into one set of data for analysis. (separate profiles are for different domains that all have identical content)
I am using a Custom Segment on each Profile to remove referral spam. I have given the Custom Segments the same name eg 'referrer spam'.
So I want to use these Custom Segments when retrieving records with the API. However have run into a challenge.
I thought I could loop through the segments and get each Profile's Id by the Custom Segment name eg 'referrer spam'. The first thing I did was loop through the Segments to see what it would give me. So I did the following:
# Authenticate and construct service.
service = get_service('analytics', 'v3', scope, key_file_location,
service_account_email)
segments = service.management().segments().list().execute()
for segment in segments.get('items', []):
print 'Segment ID ' + segment.get('id') + " - " + segment.get('name')
But this doesn't retrieve the Custom Segments, only the 'standard' Google segments eg things like:
Segment ID -1 - All Sessions
Segment ID -2 - New Users
Segment ID -3 - Returning Users
Segment ID -4 - Paid Traffic
Segment ID -5 - Organic Traffic
Segment ID -6 - Search Traffic
Segment ID -7 - Direct Traffic
Segment ID -8 - Referral Traffic
Segment ID -9 - Sessions with Conversions
Segment ID -10 - Sessions with Transactions
etc etc
So it looks like I am unable to access the Custom Segments.
I believe this has something to do with fact that I am using a Service Account and it doesn't have permissions to access the Custom Segments?
I have given the API generated developer gmail address/user read permission to all of the Profiles. I guess that isn't sufficient to get the Custom Segments.
Am I missing something? Is there a way to get Custom Segment using a Service Account? Do I need to authenticate with other than Service Account?
I found an easy way to get custom segments details from api.
First, you need to have user management access, probably an administrator can easily do that.
Manage Segments#Set Segment availability
Visit this link and go to 'Set Segment availability' section in there.
Apply 'Collaborate permission' option as shown in the link.
After applying permission, just from your service account and api run the same code as you mention in you question or follow the below link of code to list all segments details.
Listing a User's Segments
This time you will be able to get custom segment ids. I was trying to get the custom segment details since last 3-4 days. Hope it helps.
The answer is that the Analytics Core Reporting API doesn't have access to the custom segments. They can only be accessed by the Analytics Management API as referenced here:
Retrieve a user's Custom Segments to apply them to Core Reporting API queries.
https://developers.google.com/analytics/devguides/config/mgmt/v3/
So looks like I will have to make call to Analytics Management API first to get list of custom segments that I want, and then use that list in Analytics Core Reporting API call to get data for just those segments.
https://developers.google.com/analytics/devguides/reporting/core/v3/reference#segment
Alternatively, I can forget about using the custom segments and instead retrieve Session Hostname and Source in Analytics Core Reporting API call data, so that I can do same filter in the query or in report as my custom segment. Drawback is that the referral spam is about 80% + of Google Analytics data so I would be retrieving more data than i need on regular basis.

Why is custom variable data in the Google Analytics Data Export API data different from my Google Analytics dashboard?

I have a custom variable defined on my site and the data is being recorded properly in my Google Analytics account. When I go to access the data via the Google Data Feed Query Explorer, the data I get isn't the same. Really, this is only the case with 'Visits' and any metrics calculated using it.
This is what I see in my dashboard:
http://www.screencast.com/t/QJl21ZOmpw
This is what I see in the query explorer:
http://www.screencast.com/t/WNGLiUUWum
I made sure the time frame matches and have pulled the same metrics. 'Hits' (aka pageviews) match up perfectly every time. Visits is obviously off and seems to be messing up other metrics that depend on it, such as 'Pages/Visit' (aka pageviews per visit).
I have reviewed the code and the custom variable is being set prior to recording the pageview. Am I missing something? My understanding is that Google Uses this exact same API to run their Analytics Dashboard, so why am I getting different data?
Try removing the visitors metric from your feed in the Query Explorer. A "Visitor" is different than a "Visit". I believe the stats of the Google Analytics screenshot have nothing to do with visitors. And including this metric might actually limit your result set to the unique visitors (I think).