Thanks for clarifying your use case, @ryochanuedasan. What we understand you’re trying to do is the following:
- use segmented analytics data, using the asynchronous stats endpoint, to determine the effectiveness of the targeting you’ve set
- identify and remove targeting that you deem ineffective—doing this involes using attributes from the async response to match against the targeting criteria response so that you can remove the correct targeting criterion
It is possible to do this, but it depends on the targeting type. We’ll provide a few examples.
For keyword targeting, you should see something like the following for the segmented analytics data:
{
"data_type":"stats",
"time_series_length":1,
"data":[
{
"id":"5tddn",
"id_data":[
{
"segment":{
"segment_name":"API",
"segment_value":"9t1y"
},
"metrics":{
"impressions":[64],
"likes":[1],
"engagements":[14],
...
}
}
]
}
],
...
}
Making a request to the GET accounts/:account_id/targeting_criteria endpoint, you’d see something like:
$ twurl -H ads-api.twitter.com "/1/accounts/18ce54d4x5t/targeting_criteria?line_item_id=5tddn" | jq
{
"request": {
"params": {
"account_id": "18ce54d4x5t",
"line_item_id": "5tddn"
}
},
"data": [
...,
{
"line_item_id": "5tddn",
"name": "API",
"id": "9h6abl",
"account_id": "18ce54d4x5t",
"created_at": "2016-07-29T18:04:24Z",
"targeting_value": "API",
"updated_at": "2016-07-29T18:04:24Z",
"deleted": false,
"targeting_type": "PHRASE_KEYWORD"
},
...
],
"data_type": "targeting_criterion",
"total_count": 6,
"next_cursor": null
}
Note that in this case, the segment_name does equal the targeting_value.
However, if we’re looking at location targeting, the way to link is different.
{
"data_type":"stats",
"time_series_length":1,
"data":[
{
"id":"5tddn",
"id_data":[
{
"segment":{
"segment_name":"San Francisco-Oakland-San Jose CA, US",
"segment_value":"5122804691e5fecc"
},
"metrics":{
"impressions":[64],
"likes":[1],
"engagements":[14],
...
}
}
]
}
],
...
}
$ twurl -H ads-api.twitter.com "/1/accounts/18ce54d4x5t/targeting_criteria?line_item_id=5tddn" | jq
{
"request": {
"params": {
"account_id": "18ce54d4x5t",
"line_item_id": "5tddn"
}
},
"data": [
{
"line_item_id": "5tddn",
"name": "San Francisco-Oakland-San Jose CA, US",
"id": "9h69zn",
"account_id": "18ce54d4x5t",
"location_type": "CITY",
"created_at": "2016-07-29T18:03:51Z",
"targeting_value": "5122804691e5fecc",
"updated_at": "2016-07-29T18:03:51Z",
"deleted": false,
"targeting_type": "LOCATION"
},
...
],
"data_type": "targeting_criterion",
"total_count": 6,
"next_cursor": null
}
Here, the segment_name does not equal the targeting_value.
Instead, segment_value==targeting_value.
Note that there may be cases where neither approach works.
Hope this helps!