LHS/RHS operand in matchingfuntion

82 views
Skip to first unread message

Sachin Kumar

unread,
Oct 15, 2016, 11:50:54 AM10/15/16
to AdWords API Forum, Harisankar Mohanty
Hello Team,

Can you please help me in using lhs/rhs operand in matchingfunction in order to get details of locationgroup object like income tier etc. Right now though we are getting matchingfunction as null.

The response is like this:

Array
(
    [0] => CampaignCriterion Object
        (
            [campaignId] => 194515594
            [isNegative] => 
            [criterion] => LocationGroups Object
                (
                    [feedId] => 
                    [matchingFunction] => 
                    [id] => 263370580451
                    [type] => LOCATION_GROUPS
                    [CriterionType] => LocationGroups
                    [_parameterMap:Criterion:private] => Array
                        (
                            [Criterion.Type] => CriterionType
                        )

                )

            [bidModifier] => 
            [baseCampaignId] => 
            [forwardCompatibilityMap] => 
            [CampaignCriterionType] => CampaignCriterion
            [_parameterMap:CampaignCriterion:private] => Array
                (
                    [CampaignCriterion.Type] => CampaignCriterionType
                )

        )

);

The function is like this:

public function GetCampaignTargetingCriteriaExample(AdWordsUser $user, $campaignId) {
// Get the service, which loads the required classes.
$campaignCriterionService =
$user->GetService('CampaignCriterionService', 'v201607');

// Create selector.
$selector = new Selector();
$selector->fields = array('Id', 'CriteriaType');

// Create predicates.
$selector->predicates[] = new Predicate('CampaignId', 'IN', array($campaignId));

//$selector->predicates[] = new Predicate('CriteriaType', 'IN', array('LANGUAGE', 'LOCATION', 'AGE_RANGE', 'CARRIER','OPERATING_SYSTEM_VERSION', 'GENDER', 'PROXIMITY', 'PLATFORM'));
$selector->predicates[] = new Predicate('CriteriaType', 'IN', array('LOCATION_GROUPS'));

// Create paging controls.
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);

do {
// Make the get request.
$page = $campaignCriterionService->get($selector);

// Display results.
if (isset($page->entries)) {
return $page->entries;
foreach ($page->entries as $campaignCriterion) {
printf("Campaign targeting criterion with ID '%s' and type '%s' was "
. "found.\n", $campaignCriterion->criterion->id,
$campaignCriterion->criterion->CriterionType);
}
} else {
print "No campaign targeting criteria were found.\n";
}

// Advance the paging index.
$selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
} while ($page->totalNumEntries > $selector->paging->startIndex);
}

We just trying to find a way to use lhs/rhs operand inb proper way. Please help us with php code for this.


Thanks & Regards
Sachin

Joyce Lava

unread,
Oct 17, 2016, 1:26:16 AM10/17/16
to AdWords API Forum, harish....@gmail.com
Hello Sachin,

I am not a PHP expert but let's see what I can do to help. Seeing your code snippet, it looks like the campaignId and the matchingFunction are not included in the selector. Please include them and after that, for each campaignCriterion iteration, you need to cast them to a LocationGroups object. Once you have the LocationGroups object, you can now have the array of FunctionArgumentOperand which can be of type IncomeOperand (i.e. locationGroups => matchingFunction => lhsOperand and locationGroups => matchingFunction => rhsOperand). This way, you can get the income tier. The SOAP request and response should be something like this:

    <soapenv:Header>
        <ns1:RequestHeader xmlns:ns1="https://adwords.google.com/api/adwords/cm/v201607" soapenv:mustUnderstand="0">
            <ns1:clientCustomerId>YOUR_CLIENT_CUSTOMER_ID</ns1:clientCustomerId>
            <ns1:developerToken>YOUR_DEVELOPER_TOKEN</ns1:developerToken>
            <ns1:userAgent>YOUR_USER_AGENT</ns1:userAgent>
            <ns1:validateOnly>false</ns1:validateOnly>
            <ns1:partialFailure>false</ns1:partialFailure>
        </ns1:RequestHeader>
    </soapenv:Header>
    <soapenv:Body>
            <serviceSelector>
                <fields>CampaignId</fields>
                <fields>Id</fields>
                <fields>CriteriaType</fields>
                <fields>MatchingFunction</fields>
                <predicates>
                    <field>CriteriaType</field>
                    <operator>IN</operator>
                    <values>LOCATION_GROUPS</values>
                </predicates>
                <predicates>
                    <field>CampaignId</field>
                    <operator>EQUALS</operator>
                    <values>YOUR_CAMPAIGN_ID</values>
                </predicates>
                <paging>
                    <startIndex>0</startIndex>
                    <numberResults>100</numberResults>
                </paging>
            </serviceSelector>
        </get>
    </soapenv:Body>
</soapenv:Envelope>

[main] INFO com.google.api.ads.adwords.lib.client.AdWordsServiceClient.soapXmlLogger - SOAP Response:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header>
        <ResponseHeader xmlns="https://adwords.google.com/api/adwords/cm/v201607">
            <requestId>xxxxxxxxxxxxxxxxxx</requestId>
            <serviceName>CampaignCriterionService</serviceName>
            <methodName>get</methodName>
            <operations>1</operations>
            <responseTime>223</responseTime>
        </ResponseHeader>
    </soap:Header>
    <soap:Body>
        <getResponse xmlns="https://adwords.google.com/api/adwords/cm/v201607">
            <rval>
                <totalNumEntries>1</totalNumEntries>
                <Page.Type>CampaignCriterionPage</Page.Type>
                <entries>
                    <campaignId>CAMPAIGN_ID</campaignId>
                    <isNegative>false</isNegative>
                    <criterion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LocationGroups">
                        <id>CRITERIA_ID</id>
                        <type>LOCATION_GROUPS</type>
                        <Criterion.Type>LocationGroups</Criterion.Type>
                        <matchingFunction>
                            <operator>AND</operator>
                            <lhsOperand xsi:type="IncomeOperand">
                                <FunctionArgumentOperand.Type>IncomeOperand</FunctionArgumentOperand.Type>
                                <tier>TIER_6_TO_10</tier>
                            </lhsOperand>
                            <rhsOperand xsi:type="GeoTargetOperand">
                                <FunctionArgumentOperand.Type>GeoTargetOperand</FunctionArgumentOperand.Type>
                                <locations>TARGET_LOCATION_ID</locations>
                            </rhsOperand>
                            <functionString>AND()</functionString>
                        </matchingFunction>
                    </criterion>
                    <CampaignCriterion.Type>CampaignCriterion</CampaignCriterion.Type>
                </entries>
            </rval>
        </getResponse>
    </soap:Body>
</soap:Envelope>

Hope this helps.

Best,
Joyce, AdWords API Team
Reply all
Reply to author
Forward
0 new messages