Create line item with customTargeting

133 views
Skip to first unread message

Dietrich Dräyer

unread,
Mar 21, 2024, 2:39:46 AM3/21/24
to Google Ad Manager API Forum
Hello,

I found the sample "target_custom_criteria.py" showing how to extend an existing line item with custom targeting. I wonder if it is possible to add custom targeting already during the creation of a line item.

I did some modifications in the sample "create_line_items.py". With adding of 'geoTargeting' I was successful. With 'customTargeting' it seems to be very complicated. I do not fully understand the nested structure in the documentation type CustomCriteriaSet (v202402)  |  Ad Manager API  |  Google for Developers.

Is there an example helping me to write a well working 'customTargeting' section in my "create_line_items_modified.py"?

Excerpt:

.. snip ..
  # Create line item objects.
  line_items = []
  for _ in range(1):
    line_item = {
        # 'name': 'Line item #%s' % uuid.uuid4(),
        'name': 'Post_RoN_Broad_FR',
        'orderId': order_id,
        'targeting': {
            'geoTargeting': {
                'targetedLocations': [{'id': '20126'}, {'id': '20143'}, {'id': '20151'}]
            },
            'inventoryTargeting': {
                'targetedPlacementIds': targeted_placement_ids
            },            
            'technologyTargeting': {
                'browserLanguageTargeting': {
                    'browserLanguages': [{'id': '504001'}, {'id': '504004'}],
                    'isTargeted': 'false'
                }
            },
            'customTargeting': {
                'CustomCriteriaSet': [ ... ??? ... ]
            }
        },
.. snip ..

Many thanks for your hints in advance and cheers,

Dietrich
  # Create line item objects.
  line_items = []
  for _ in range(1):
    line_item = {
        # 'name': 'Line item #%s' % uuid.uuid4(),
        'name': 'Post_RoN_Broad_FR',
        'orderId': order_id,
        'targeting': {
            'geoTargeting': {
                'targetedLocations': [{'id': '20126'}, {'id': '20143'}, {'id': '20151'}]
            },
            'inventoryTargeting': {
                'targetedPlacementIds': targeted_placement_ids
            },            
            'technologyTargeting': {
                'browserLanguageTargeting': {
                    'browserLanguages': [{'id': '504001'}, {'id': '504004'}],
                    'isTargeted': 'false'
                }
            },
            'customTargeting': {
                'CustomCriteriaSet': [ ... ??? ... ]
            }
        },
  # Create line item objects.
  line_items = []
  for _ in range(1):
    line_item = {
        # 'name': 'Line item #%s' % uuid.uuid4(),
        'name': 'Post_RoN_Broad_FR',
        'orderId': order_id,
        'targeting': {
            'geoTargeting': {
                'targetedLocations': [{'id': '20126'}, {'id': '20143'}, {'id': '20151'}]
            },
            'inventoryTargeting': {
                'targetedPlacementIds': targeted_placement_ids
            },            
            'technologyTargeting': {
                'browserLanguageTargeting': {
                    'browserLanguages': [{'id': '504001'}, {'id': '504004'}],
                    'isTargeted': 'false'
                }
            },
            'customTargeting': {
                'CustomCriteriaSet': [ ... ??? ... ]
            }
        },

Ad Manager API Forum Advisor

unread,
Mar 21, 2024, 6:16:01 AM3/21/24
to google-doubleclick...@googlegroups.com
Hi,

Thank you for contacting the Ad Manager API support team.

According to the API documentation, the customTargeting will have up to three levels of expressions including itself.  Here is the sample python code for your reference to create Custom Criteria, refer to this link for detailed information.

Example code snippet:
 <children xsi:type="ns0:CustomCriteriaSet">
                                <logicalOperator>OR</logicalOperator>
                                <children xsi:type="ns2:CustomCriteria">
                                    <keyId>xxxxxxxx</keyId>
                                    <valueIds>xxxxxxxx</valueIds>
                                    <operator>IS</operator>
                                </children>

Hope this helps.

 
This message is in relation to case "ref:!00D1U01174p.!5004Q02s07sc:ref" (ADR-00228163)

Thanks,
 
Google Logo Ad Manager API Team


 

Dietrich Dräyer

unread,
Mar 21, 2024, 11:41:58 AM3/21/24
to Google Ad Manager API Forum
Hello,

thanks for your valuable help. With the following code snippet I was succesful.

.. snip ..
# Create custom criterias
  custom_criteria1 = {
      'xsi_type': 'AudienceSegmentCriteria',
      'audienceSegmentIds': [audience_segment_id1],
      'operator': 'IS'
  }

  custom_criteria2 = {
      'xsi_type': 'AudienceSegmentCriteria',
      'audienceSegmentIds': [audience_segment_id2],
      'operator': 'IS'
  }
 
  custom_criteria3 = {
      'xsi_type': 'AudienceSegmentCriteria',
      'audienceSegmentIds': [audience_segment_id3, audience_segment_id4],
      'operator': 'IS_NOT'
  }
 
  # Create the custom criteria set
  sub_set = {
      'xsi_type': 'CustomCriteriaSet',
      'logicalOperator': 'AND',
      'children': [custom_criteria2, custom_criteria3]
  }
 
  top_set = {
      'xsi_type': 'CustomCriteriaSet',
      'logicalOperator': 'OR',
      'children': [custom_criteria1, sub_set]

  }
   
  # Create line item objects.
  line_items = []
  for _ in range(1):
    line_item = {
        # 'name': 'Line item #%s' % uuid.uuid4(),
        'name': 'Post_RoN_Broad_FR',
        'orderId': order_id,
        'targeting': {
            'geoTargeting': {
                'targetedLocations': [{'id': '20126'}, {'id': '20143'}, {'id': '20151'}]
            },
            'inventoryTargeting': {
                'targetedPlacementIds': targeted_placement_ids
            },            
            'technologyTargeting': {
                'browserLanguageTargeting': {
                    'browserLanguages': [{'id': '504001'}, {'id': '504004'}],
                    'isTargeted': 'false'
                }
            },
            'customTargeting': top_set
        },
     
.. snip ..

Cheers, Dietrich

Reply all
Reply to author
Forward
0 new messages