Audience Segment creation

97 views
Skip to first unread message

Josef Adlao

unread,
Apr 1, 2025, 4:22:03 AMApr 1
to Google Ad Manager API Forum
Hi,

Are we able to use the API to create first party audience segments that are pixel-based?

Ad Manager API Forum Advisor

unread,
Apr 1, 2025, 10:44:22 AMApr 1
to google-doubleclick...@googlegroups.com

Hi,

Thank you for contacting the Ad Manager API support team.

I would like to inform you that the"population method" option is only available in the Ad Manager UI. I will raise a request to add this feature in the Ad Manager API. With that being said, I am unable to comment about the availability of this feature in the API. I'd advise you to follow our Blog Post and Release Notes for announcements about new API releases and features. 

Although there is no field that directly corresponds to the UI's Population Method, you can create "Publisher Managed" segments by creating a NonRuleBasedFirstPartyAudienceSegment . Similarly, you can create a Traffic based segment by creating a RuleBasedFirstPartyAudienceSegment . For pixel tracking, you can set the Targeting of the RuleBasedFirstPartyAudienceSegment to target the audience pixel ad unit and manually create custom criteria.

 

Thanks,
 
Google Logo Ad Manager API Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5
[2025-04-01 14:43:55Z GMT] This message is in relation to case "ref:!00D1U01174p.!5004Q02vHEOk:ref" (ADR-00297920)



Jóse L. Méndez Cordova

unread,
Jul 7, 2025, 9:40:08 PMJul 7
to Ad Manager API Forum Advisor, google-doubleclick...@googlegroups.com
Dear Ad Manager API Support Team,

Thank you for your previous response and for the clarification regarding the audience segment population method and the use of RuleBasedFirstPartyAudienceSegment for traffic-based segmentation.

I am currently trying to implement a pixel-based audience segment using the Ad Manager API, but I have not been able to successfully create one despite several attempts. I understand from your documentation and support response that this involves creating a RuleBasedFirstPartyAudienceSegment and setting the rules to match the audience pixel ad unit.

Could you please provide a working example (preferably in Python, Php or Java) showing how to create a pixel-based audience segment via the API? If available, a link to an example in your GitHub repository or other relevant documentation would be very helpful.

Specifically, I am looking for:

  • A full example of how to create a RuleBasedFirstPartyAudienceSegment

  • How to configure the targeting rules using ad unit criteria

  • How to simulate the behavior of a pixel-based population method via the API

I have reviewed the API reference and blog posts, but I have not found a complete working example. Any assistance or guidance would be greatly appreciated.


--
You received this message because you are subscribed to the Google Groups "Google Ad Manager API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-doubleclick-for-p...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-doubleclick-for-publishers-api/CYkgo000000000000000000000000000000000000000000000SU1NL700xV8Kd6rXTAWR38oIhQenuw%40sfdc.net.

Ad Manager API Forum Advisor

unread,
Jul 8, 2025, 3:47:49 AMJul 8
to lic1...@gmail.com, google-doubleclick...@googlegroups.com

Hi,

Thank you for reaching out to the  Ad Manager API support team.

A pixel based segment is an instance of a RuleBasedFirstPartyAudienceSegment with a particular rule configuration:

  • The inventoryRule must target only the audience pixel ad unit.
  • The customCriteriaRule must target only a self-referencing custom targeting value under the Audience Pixel ID key.

The easiest way to do this is to use an existing pixel based segment as a template. Here are the steps:

  1. Read an existing pixel based segment using GetAudienceSegmentsByStatement.
  2. Extract the Audience Pixel ID CustomTargetingKeyId from the customCriteriaRule and the ad unit ID from the inventoryRule.
  3. Create a new RuleBasedFirstPartyAudienceSegment. Set the inventoryRule targeting the audience pixel ad unit and the customCriteriaRule targeting any existing custom targeting value.
  4. From the CreateAudienceSegments response, get the ID of your new segment.
  5. Create a new CustomTargetingValue under the Audience Pixel key. Set the name to the ID of your new segment.
  6. Update your new segment to target the new CustomTargetingValue from step 5.
  7. Verify your configuration is correct in the UI. You should see the text "You have chosen to use this segment as an Audience pixel tag." above the targeting for your segment.

To create RuleBasedFirstPartyAudienceSegment, I recommend using the createAudienceSegments() in the AudienceSegmentService. Here is the sample code for creating a RuleBasedFirstPartyAudienceSegment in java. You may refer to all available client libraries for the Ad Manager API.


Thanks,
 
Google Logo Ad Manager API Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5

[2025-07-08 07:47:29Z GMT] This message is in relation to case "ref:!00D1U01174p.!5004Q02vHEOk:ref" (ADR-00297920)



Jóse L. Méndez Cordova

unread,
Jul 8, 2025, 4:36:01 AMJul 8
to Ad Manager API Forum Advisor, google-doubleclick...@googlegroups.com

Hello Support Team,

I hope you're doing well.

I’m currently working on creating a pixel-based audience segment using the Ad Manager API by implementing a RuleBasedFirstPartyAudienceSegment. I'm including AdUnit-level targeting and setting the required parameters such as pageViews, recencyDays, and membershipExpirationDays.

Attached below is a minimal reproducible PHP example demonstrating how I’m setting this up via the API.
My goal is to have the “Generate Tag” option available in the UI under Inventory > Audience segments, but unfortunately, the “Generate Tag” button does not appear after the segment is created—even when the type is confirmed to be RULE_BASED.

Could you please confirm the following?

  1. Is this implementation pattern correct to trigger a pixel-based segment creation?

  2. What are the exact conditions or steps required for the “Generate Tag” button to appear in the Google Ad Manager UI for a RuleBasedFirstPartyAudienceSegment?

  3. Is there any delay or post-creation processing time before this feature becomes available?

Any guidance or official documentation on this would be highly appreciated. I’ve been testing with various rule combinations, but haven’t been able to activate the tag generation option yet.




<?php

require __DIR__ . '/vendor/autoload.php'; // Ajustado para ruta genérica

use Google\AdsApi\Common\OAuth2TokenBuilder;
use Google\AdsApi\AdManager\AdManagerSessionBuilder;
use Google\AdsApi\AdManager\v202408\ServiceFactory;
use Google\AdsApi\AdManager\v202408\RuleBasedFirstPartyAudienceSegment;
use Google\AdsApi\AdManager\v202408\FirstPartyAudienceSegmentRule;
use Google\AdsApi\AdManager\v202408\InventoryTargeting;
use Google\AdsApi\AdManager\v202408\AdUnitTargeting;
use Google\AdsApi\AdManager\Util\v202408\StatementBuilder;

class PixelAudienceCreator {

    private $serviceFactory;
    private $session;

    public function __construct() {
        $this->initializeSession();
    }

    private function initializeSession() {
        // ⚠️ Reemplazar 'path/to/config.ini' con ruta real al archivo de configuración
        $oAuth2Credential = (new OAuth2TokenBuilder())
            ->fromFile('path/to/config.ini')
            ->build();

        $this->session = (new AdManagerSessionBuilder())
            ->fromFile('path/to/config.ini')
            ->withOAuth2Credential($oAuth2Credential)
            ->build();

        $this->serviceFactory = new ServiceFactory();
    }

    public function createRuleBasedPixelAudience($name, $description = '', $adUnitId, $membershipExpirationDays = 30) {
        $audienceSegmentService = $this->serviceFactory->createAudienceSegmentService($this->session);

        $audienceSegment = new RuleBasedFirstPartyAudienceSegment();
        $audienceSegment->setName($name);
        $audienceSegment->setDescription($description);
        $audienceSegment->setStatus('ACTIVE');
        $audienceSegment->setPageViews(1);
        $audienceSegment->setRecencyDays(1);
        $audienceSegment->setMembershipExpirationDays($membershipExpirationDays);

        $rule = new FirstPartyAudienceSegmentRule();

        $inventoryTargeting = new InventoryTargeting();
        $adUnitTargeting = new AdUnitTargeting();
        $adUnitTargeting->setAdUnitId($adUnitId);
        $adUnitTargeting->setIncludeDescendants(true);
        $inventoryTargeting->setTargetedAdUnits([$adUnitTargeting]);

        $rule->setInventoryRule($inventoryTargeting);
        $audienceSegment->setRule($rule);

        $results = $audienceSegmentService->createAudienceSegments([$audienceSegment]);

        if (!empty($results)) {
            $createdSegment = $results[0];
            printf("Created RULE_BASED Audience Segment with ID %d and name '%s'\n",
                $createdSegment->getId(), $createdSegment->getName());
            return $createdSegment;
        }

        return null;
    }

    public function getAvailableAdUnits($limit = 5) {
        $inventoryService = $this->serviceFactory->createInventoryService($this->session);

        $statementBuilder = (new StatementBuilder())
            ->orderBy('name ASC')
            ->limit($limit);

        $page = $inventoryService->getAdUnitsByStatement($statementBuilder->toStatement());

        $adUnits = [];

        if ($page->getResults()) {
            foreach ($page->getResults() as $adUnit) {
                $adUnits[] = [
                    'id' => $adUnit->getId(),
                    'name' => $adUnit->getName(),
                ];
            }
        }

        return $adUnits;
    }
}

// 🧪 Example usage (requires valid AdUnit ID from your network)
$creator = new PixelAudienceCreator();

// Replace this with your own AdUnit ID for testing
$adUnits = $creator->getAvailableAdUnits();
if (!empty($adUnits)) {
    $adUnitId = $adUnits[0]['id'];

    $creator->createRuleBasedPixelAudience(
        'Test Pixel-Based Segment - ' . date('Y-m-d H:i:s'),
        'Sample pixel-based RULE_BASED audience segment',
        $adUnitId
    );
} else {
    echo "No AdUnits found.\n";
}

?>

Response execut code
 Authenticating...
Successfully authenticated.
Retrieving available AdUnits...
Fetching list of available AdUnits...
AdUnits found:
   - ID: [REDACTED] | Name: Sample AdUnit
   - ID: [REDACTED] | Name: Sample AdUnit
   - ID: [REDACTED] | Name: Sample AdUnit

==================================================
Creating RULE_BASED audience for pixel...
Creating RULE_BASED audience segment: Pixel Audience RULE_BASED - [Timestamp]
RULE_BASED audience segment successfully created:
   ID: [REDACTED]
   Name: Pixel Audience RULE_BASED - [Timestamp]
   Status: ACTIVE
   Type: FIRST_PARTY
   AdUnit ID: [REDACTED]

AUDIENCE TYPE VERIFICATION:
=======================================
Detected type: FIRST_PARTY
Status: ACTIVE
 ISSUE: Type is FIRST_PARTY, not RULE_BASED
The "Generate Tag" button may not be available

🔧 POSSIBLE SOLUTIONS:
1. Wait 5–10 minutes and refresh Ad Manager UI
2. Ensure the audience segment has targeting rules defined
3. Try creating another audience with more specific targeting

📝 ADDITIONAL INFO:
- Audience ID: [REDACTED]
- Name: Pixel Audience RULE_BASED - [Timestamp]
- You can mention these details to Google Support
=======================================

SUCCESS! RULE_BASED audience created
 ID: [REDACTED]

Fetching detailed information...
Getting detailed info for audience ID: [REDACTED]
DETAILED INFORMATION:
========================
ID: [REDACTED]
Name: Pixel Audience RULE_BASED - [Timestamp]
Type: FIRST_PARTY
Status: ACTIVE
Description: Pixel-based RULE_BASED audience segment
Size: 0
Membership duration (days): 30
Page views: 1
Recency (days): 1
Targeting rules are defined

NEXT STEPS:
1. Go to Google Ad Manager
2. Navigate to: Inventory → Audience segments
3. Locate: Pixel Audience RULE_BASED - [Timestamp]
4. Click on the audience name
5. Look for the “Generate Tag” button
6. If not visible, wait 5–10 minutes and refresh

Not activate  “Generate Tag” 

Thank you very much in advance!

Google Ad Manager API Forum

unread,
Jul 9, 2025, 6:17:18 PMJul 9
to Google Ad Manager API Forum
Hi,

Please find the below response to your queries respectively.


Is this implementation pattern correct to trigger a pixel-based segment creation?

I have checked your code and the implementation pattern is correct to trigeer a pixel-based segment creation via API.


What are the exact conditions or steps required for the “Generate Tag” button to appear in the Google Ad Manager UI for a RuleBasedFirstPartyAudienceSegment?

Please note that the 'Generate Tag' feature only appears for a specific type of first-party audience segment, those explicitly designated as 'Pixel-based' during creation in the UI. As you are creating RuleBasedFirstPartyAudienceSegment via API, which is not the same as the 'Pixel-based' option you see in the UI. So, it is not possible enable the 'Generate Tag' button for a RuleBasedFirstPartyAudienceSegment via API.


Is there any delay or post-creation processing time before this feature becomes available?

It is not possible enable the 'Generate Tag' button feature for a RuleBasedFirstPartyAudienceSegment via API.

Also, from the provdided information, I observed that you are using v202408 version of Ad Manager API. I can confirm that the v202408 version of the Ad Manager API is deprecated and about to sunset in August 2025. Please note that the v202505 version is the current latest version. I would recommend you to please migrate to the latest version of the Ad Manager API to avoid any issues. You may check all available versions and deprecation schedules of the Ad Manager API. You can also refer to the all available client libraries for the Ad Manager API. The developer of these applications will need to update their code to call a supported API version.

Hope this answers your query. If you have any more queries, please feel free to get back to us.

Regards,
Ad Manager API Team.

Reply all
Reply to author
Forward
0 new messages