Google Analytics - Can I create VISITOR based dynamic segments in the API? - google-analytics-api

This is an EXPERT Google analytics question (you've been warned).
In the GA user interface I can create a segment based on a USER and not a VISIT.
When using the dynamic segments in the API I've discovered the segment is VISIT based.
Is is possible to tell the API I want to create a dynamic segment based on USER instead (like in the GUI)?

I looked into this some more and found that as of Dec 13, 2013 it is NOT possible to create dynamic user based segments via the API.

The problem is, that you even cant retrieve Id of Segment with visitor filtration, even if exists in Web interface.

Related

Creating a report with GA4 data API and using segments

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!

Facebook marketing API Does not select the correct pixel conversion event

I'v built an app that creates ads using the marketing API. When it creates the adset it sets a specific pixel and a page view event.
All our users get the correct pixel and the correct event except for one user.
Here is the object from the post request that is being sent to Facebook where we can see that they are equal
User one
"promoted_object":"{\"pixel_id\":xxxxxxxxxx63,\"custom_event_type\":\"CONTENT_VIEW\",\"pixel_rule\":\"{\\\"event\\\":{\\\"eq\\\":\\\"PageView\\\"}}\"
User two
"promoted_object":"{\"pixel_id\":xxxxxxxxxx63,\"custom_event_type\":\"CONTENT_VIEW\",\"pixel_rule\":\"{\\\"event\\\":{\\\"eq\\\":\\\"PageView\\\"}}\"
Both get the correct pixel with the correct id but one gets no conversion event, and say Missing conversion event.
Both ad accounts have full access to the pixel under the business settings in ads manager.
Here is an image that describes the issue.
Anyone have any ideas here?
make sure the conversion event is defined in that account.
The conversion event is usually set on Campaign Level and supplied when you create a campaign via API.
As you're trying to use a custom conversion it might be that you've created it for one account but didn't create it for another. That's why you don't see it in you campaign setup view. You can create it via API as described here:
Custom Conversion API
Or just do it via Business Manager and use it afterward when creating you campaigns via API or manually.
It's definitely not a request that fails in this case but a proper account configuration.

General question about SmartSheet API and creating a user interface

My company keeps individual employee schedules. Each employee manages their own schedule. Admin,supervisors and project manager have to go to each sheet and look for the information.
I need to create a system that allows someone to select a date range and skill set then produce a sheet with the information that matches the criteria. I have installed the Python API and worked through a few tutorials.
Now I need to know how to make command buttons, date pickers . . .
A quick read of my search results indicates that this is not part of the Smartsheet API!
Is there a way to do this through the SmartSheet API? Or how would you approach this?
The Smartsheet API enables you to programmatically access data in Smartsheet (i.e., create, read, update, delete data in Smartsheet). This is true for all APIs -- they simply provide a means for you to programmatically access data. You'll need to build the web app's user interface (UI) yourself by using HTML, CSS, JavaScript, etc.
Alternatively -- instead of building a custom web application like you've described -- I'd suggest that you look into the possibility of creating Smartsheet Reports that can provide the data you've described. You can create Smartsheet Reports via the Smartsheet UI -- so you wouldn't need to do any programming at all.

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.

Get page visitors from google analytics API

Reading Google Analytics API docs is like diving into Mariana Trench... so hoping to get some help here.
I have a website that users will visit one page per visit (most of the time). I've placed google analytics script on each page (can view reports in my GA account) and now want to write a "reporting page" on which to display information about "per page usage":
page1: 100 visitors, countries, OSes, ...
page2: 125 visitors, countries, OSes, ...
I want to get this info from API.
Could some one please point me to the right pages of the docs, from the very beginning?
For I can't understand even why I should use 2-step OAuth authorization there (or shouldn't I?) - since I'm writing this report for my own site on which I have already placed google scripts thus authorizing everything.
Thank you.
What i am thinking is that I could have a Webapplication with your pages listed. Web application itself is authenticating and querying the result on when user try to find statistics of particular page.
You should follow
1. Register Service account and get authentication key file
2. Register email account viewed in along clientid email a screen in google analytic users as admin level user
3. Use ga-dev-tools.appspot.com/explorer for query building
4.Implemenation needs
a) First Authenticate with the key
b) Get profile id and pass it to the fetching method
c) Fetch data of the query