How I can get "stats_data" that corresponds to "master data" about keywords

targeting
api
stats

#1

Hi! :stuck_out_tongue:

I’m wondering how I can acquire “stats_data” that corresponds to “master data” of keywords.

I can fetch “stats_data” about keywords from this API with params ({ segmentation_type: KEYWORDS, entity: LINE_ITEM}): https://dev.twitter.com/ads/reference/1/post/stats/jobs/accounts/%3Aaccount_id

ex) acquired data
{
  "data_type": "stats",
  "time_series_length": 7,
  "data": [
    {
      "id": "69ob",
      "id_data": [
        {
          "segment": {
            "segment_name": "this is targeting keyword",
            "segment_value": "XXXXXXX"                             <==== this value 
          },

And keyword’s “master_data” can be fetched from this API ({ https://dev.twitter.com/ads/reference/get/accounts/%3Aaccount_id/targeting_criteria }). There are some targeting criteria whose targeting type include ‘KEYWORD’.

ex)
{
    "account_id": "hkk5", 
    "created_at": "2012-12-05T05:11:15Z", 
    "deleted": true, 
    "id": "YYYYYYY",                                               <==== this value 
    "line_item_id": "69ob", 
    "name": "righteous dude", 
    "targeting_type": "PHRASE_KEYWORD", 
    "targeting_value": "this is targeting keyword", 
    "updated_at": "2012-12-05T05:11:15Z"
}

Are there any relationship between these data? Should “segmentation_value” of “stats_data” (XXXXXXX above) and “id” of “targeting_criteria” (YYYYYYY above) become equal?


#2

Thanks for the question, @ryochanuedasan, and for providing those details. This is in our queue and we’ll update you as soon as we can.


#3

Thank you for your reply!


#4

@juanshishido I want to ask one more question, is it correct that to join data “stats” and “master” on “line_item_id” and “name”(segment_name) so far?


#5

@ryochanuedasan: The id attribute you see when calling the GET accounts/:account_id/targeting_criteria endpoint is a unique identifier for the targeting that’s been created and does not correspond to segment_value.

In many cases, though, segment_value matches the targeting_value you’d see when calling any of the /1/targeting_criteria endpoints. For example:

$ twurl -H ads-api.twitter.com "/1/accounts/{account_id}/targeting_criteria?line_item_id={line_item_id}" | jq
{
  "request": {
    "params": {
      "account_id": {account_id},
      "line_item_id": {line_item_id}
    }
  },
  "data": [
    {
      "line_item_id": {line_item_id},
      "name": "San Francisco-Oakland-San Jose CA, US",
      "id": "9h69zn",
      "account_id": {account_id},
      "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
}
$ twurl -H ads-api.twitter.com "/1/targeting_criteria/locations?q=san francisco" | jq
{
  "data_type": "targeting_criterion",
  "data": [
    ...,
    {
      "name": "San Francisco-Oakland-San Jose CA, CA, USA",
      "country_code": "US",
      "location_type": "CITY",
      "targeting_value": "5122804691e5fecc",
      "targeting_type": "LOCATION"
    },
    ...
  ],
  "request": {
    "params": {
      "q": "san francisco"
    }
  },
  "next_cursor": null
}

Note the matching 5122804691e5fecc values.


In terms of your second question, could you please clarify what you’re trying to do?


#6

@ryochanuedasan: Did we help clarify things?


#7

@juanshishido I’m sorry for my late reply and poor English!
As you can see in the first post, I wanted to measure which keyword targeting has been effective and delete ineffective keyword targeting.
In my opinion, “stats_data” of keywords can be specified in unique key(“line_item_id”, “segment_name”, and date)
, and I can delete ineffective targeting keyword from “POST targeting_criteria” by those parameters(“segment_name” matches “targeting_value”, right?).


#9

Thanks for clarifying your use case, @ryochanuedasan. What we understand you’re trying to do is the following:

  1. use segmented analytics data, using the asynchronous stats endpoint, to determine the effectiveness of the targeting you’ve set
  2. 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!


#10

Thank you for your quick and polite reply!
I was able to understand well :grinning:


#11

Thanks for confirming, @ryochanuedasan. If you have any other questions, please reach out again.


#12

@ryochanuedasan: Please consider marking this thread as resolved.