Setting Conversion Window/Ads Action Stats via Facebook Ads Api - facebook

I have a requirement to add 'Conversion Window' (as above) to an existing Java application which creates batches of Facebook ads. I can't find how to set Conversion Window via the API or how to get a list of them from the API.
This is the most relevant information I've found:
https://developers.facebook.com/docs/marketing-api/reference/ads-action-stats
But it doesn't give me all of what I need.

Although named similarly, those are two different things.
Conversion window specified with bidding is a time period used for optimization of ad delivery. The parameter is called attribution_specand can be set on adset. Valid combinations are described here.
Adset with conversion window of 1-day view, 7-day click would be specified like this:
{
"name": "Adset name",
"attribution_spec": [
{
"event_type": "VIEW_THROUGH",
"window_days": 1
},
{
"event_type": "CLICK_THROUGH",
"window_days": 7
}
],
... other adset params ...
}
Attribution window is a parameter used when loading insights. Using that you can get the stats broken down into different time periods, which can be handy for advanced analytics.

Related

Google Analytics 4 Measurement Protocol shows events but no users

I would like to use Google Analytics from a script (using explicit HTTP requests) and understand that Google Analytics 4 with the Measurement Protocol would be the way to go. I have created a new Property, added a Web tag and created an API key for the Measurement Protocol there. Then I send this request:
{
"client_id": "Test-User",
"user_id": "test_user_id",
"events": [
{
"name": "MyEvent",
"params": {}
}
]
}
To this URL: https://www.google-analytics.com/mp/collect?measurement_id=G-LQDLGRLGZS&api_secret=JXGZ_CyvTt29ucNi9y0DkA
The measurement gets logged there in a corner of the report:
These events don't show up as users. And in reports I don't quite see how to analyze these events. Is there some way to track user sessions by sending special events?
I had the same problem and the answer is here
GA4 Measurement Protocol returns events not the users
Under the events branch of the JSON, when I added
"engagement_time_msec" : 1
the users started to be counted.
"events" : [{
"name" : "SoftMeter_event",
"params" : {
"action" : "From UA-xxxxx [muted]",
"engagement_time_msec" : 1,
"label" : "SoftMeter-dev/v1.0.2/lib v1.4.4 DEBUG"
}
}],
The Measurement Protocol V4 is for GA4 properties(which is also the
one you are using).
According to the official document:
https://support.google.com/analytics/answer/9408920 It says "Google
Analytics 4 properties counts users who engaged with your app/site for
any non-zero amount of time during the previous 30 minutes".
GA4 uses "engagement_time_msec" parameter to identify user interaction
time. This explains why you can see the number of events but not the
number of users. If you want users sent from MP to be counted as
active user, simply add the "engagement_time_msec" parameter to your
event.
client_id is wrong. This id is set by google, so you should get your real id.
You can get it from your cookies for testing. Or, if you use gtag.js you can add this code to your web page.
<script>
gtag('get', <yourMeasurementID>, 'client_id', (clientID) => {
// here you can use clientID
});
</script>

how to query custom dimension google anaylitics api

I have setup a custom dimension in google analytics 'dimension2' into which I want to capture a WPForms UniqueID. I added this to Google Tag manager and I can see the custom dimension with a value when I preview site in GTA preview.
. I added this to gtags.js on this word press site,
var dimensionValue = $.cookie("_wpfuuid");
gtag('config', 'UA-1234567890-2', {
'custom_map': {'dimension2': 'wpfid'}
});
gtag('set', 'dimension2', {'wpfid': dimensionValue});
In google analytics query explorer, I can see dimension2 in the test results.
"columnHeaders": [
{
"name": "ga:dimension2",
"columnType": "DIMENSION",
"dataType": "STRING"
},
{
"name": "ga:users",
"columnType": "METRIC",
"dataType": "INTEGER"
}
],
"totalsForAllResults": {
"ga:users": "1"
},
"rows": [
[
"40502794-ecf1-4cf6-97b9-2c16c7f6c949",
"1"
]
]
And, I can see the dimension2 data in google analytics user explorer, so it is making it to the browser interface for analytics.
However, when I add the following to my API query script, it breaks and is not generating any php errors, or the error is that it does not recognize 'dimension2'. I tried this on 2 views and both act the same. Here is my code to add the custom dimension to my query
$dimension = new Google_Service_AnalyticsReporting_Dimension();
$dimension->setName("ga:dimension2");
What am I missing? Why isn't this visible in google api results and/or where I can I see any errors?
Some hours later, this code started to work, which suggests to me that custom dimensions are not immediately available to the api. In this case the api recognized dimension2 long after the data was visible in the analytics website.
Second possibility to check which can cause this seemingly good code to not work, you are using the wrong view id. Of the 2 views I tested, this only works on one.

Custom Dimensions Not Reporting Through to Google Analytics API V4

I am attempting to pass information collected as, "custom dimensions," from Google Tag Manager through Google Analytics and then extract them out via the Google Analytics V4 API.
I have set up four of the fundamental custom dimensions suggested by Simo Ahava in this article.
My variable setup looks like the following:
variable setup
Essentially, I have been able to successfully pass through userID_dimension, hittimestamp_dimension, clientid_dimension and sessionid_dimension to the Google Analytics dashboard, but for some reason I am not able to extract out the hittimestamp_dimension through the API.
Here's what I am able to see on the dashboard:
Google Analytics Dashboard
As far as the API itself, I am using the HelloAnalytics.py python version supplied by Google, and I am able to extract out all of the above information, minus the timestamps dimensions on the right hand side of each.
I'm storing the timestamp information in dimension2, but upon making the below call (again, using API V4) I get blank...nothing.
analytics.reports().batchGet(
body={
'reportRequests': [
{
'viewId': VIEW_ID,
'dateRanges': [{'startDate': '2017-10-05', 'endDate': '2017-10-06'}],
'samplingLevel': 'LARGE',
'dimensions': [{'name': 'ga:dimension4'},{'name': 'ga:dimension2'}]
}]
}
).execute()
Upon making this call, one would expect that the above would report out dimensions similar to what the Google Analytics dashboard would show. E.g. one would think that the dashboard itself is using the API. However what prints out is blank. All other custom dimensions print out as expected.
If I try to call the above function on just dimension2 itself with no other dimension, it is also blank.
Is there something special one has to do in order to extract hit-scoped variables within the API? Or does the API just not allow hit-scoped variables to pass through?
thanks,
You forgot to add a 'metrics' field to your request, it is required as per documentation
Source: Reporting API v4 - Method: reports.batchGet
The metrics requested. Requests must specify at least one metric. Requests can have a total of 10 metrics.
The below modified request should work:
analytics.reports().batchGet(
body={
'reportRequests': [
{
'viewId': VIEW_ID,
'dateRanges': [{'startDate': '2017-10-05', 'endDate': '2017-10-06'}],
'samplingLevel': 'LARGE',
'dimensions': [{'name': 'ga:dimension4'},{'name': 'ga:dimension2'}],
'metrics': [{'expression': 'ga:sessions'}]
}]
}
).execute()

Getting active time from Google Fit Rest API

I am struggling with matching the "active time" returned by Fit REST API with reality.
As an example - on 12/14 I had two walks, about 45 minutes each. The api returns one of them as type 7 ("walking" - right!) and another one as type 0 (in vehicle - wrong!). However, Fit app shows both as "walking", so it apparently uses a different data source.
I checked some other days and on these days, the session with type 0 is indeed a valid "in vehicle" session.
I tried all aggregated data sources that return com.google.activity.segment. Most of them are empty, I've found data only in merge_activity_segments and platform_activity_segments (and they seem to be identical).
Google's docs have a caveat about delay in data sync, but they never specified how long this delay is. The data I am looking at is about 24 hours old - if their sync is that slow, then this API is more or less unusable.
I am using the following POST to https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate
{
"aggregateBy": [
{
"dataSourceId": "derived:com.google.activity.segment:com.google.android.gms:merge_activity_segments"
}
],
"endTimeMillis": "1481788800000",
"startTimeMillis": "1481702400000",
"bucketByTime": {
"period": {
"timeZoneId": "America/Los_Angeles",
"type": "day",
"value": 1
}
}
}
For reference - activity types: https://developers.google.com/fit/rest/v1/reference/activity-types
Has anyone been able to retrieve activity time from Fit's REST API that is correct? Any suggestions?
By the way, steps and calories seem to work fine - just aggregate the following datasets:derived:com.google.calories.expended:com.google.android.gms:merge_calories_expended and derived:com.google.step_count.delta:com.google.android.gms:estimated_steps
A side note - it is probably the worst documented API from a major company I have seen.

Breakdown parameters for the application insights

According to the Facebook documentation for the app insights (link) one can specify breakdowns parameters, namely app_event_parameter1, app_event_parameter2 etc. However, I failed to find any information how to do it. So, the question is where and how exactly to specify these parameters?
The names app_event_parameter1, ..., app_event_parameter10 are slightly misleading since the other breakdowns in the table are used exactly as listed.
For example, you would request the breakdowns client and auth_state like this:
{
"period": "monthly",
"breakdowns[0]": "client",
"breakdowns[1]": "auth_state"
}
However, if you've been logging a custom app event with a custom parameter "game_level" then you'd request that breakdown like this:
{
"period": "monthly",
"breakdowns[0]": "game_level",
}
You can supply up to 10 of your own app event parameter names as breakdowns.