examples/AdWords/v201809/Remarketing/AddRuleBasedUserLists.php
private static function createUserListRule()
    {
        // First rule item group - users who visited the checkout page and had more
        // than one item in their shopping cart.
        $checkoutStringRuleItem = new StringRuleItem();
        $checkoutStringKey = new StringKey();
        $checkoutStringKey->setName('ecomm_pagetype');
        $checkoutStringRuleItem->setKey($checkoutStringKey);
        $checkoutStringRuleItem->setOp(StringRuleItemStringOperator::EQUALS);
        $checkoutStringRuleItem->setValue('checkout');
        $checkoutRuleItem = new RuleItem();
        $checkoutRuleItem->setStringRuleItem($checkoutStringRuleItem);

        $cartSizeNumberRuleItem = new NumberRuleItem();
        $cartSizeNumberKey = new NumberKey();
        $cartSizeNumberKey->setName('cartsize');
        $cartSizeNumberRuleItem->setKey($cartSizeNumberKey);
        $cartSizeNumberRuleItem->setOp(NumberRuleItemNumberOperator::GREATER_THAN);
        $cartSizeNumberRuleItem->setValue(1.0);
        $cartSizeRuleItem = new RuleItem();
        $cartSizeRuleItem->setNumberRuleItem($cartSizeNumberRuleItem);

        // Combine the two rule items into a RuleItemGroup so AdWords will AND their
        // rules together.
        $checkoutMultipleItemGroup = new RuleItemGroup();
        $checkoutMultipleItemGroup->setItems(
            [$checkoutRuleItem, $cartSizeRuleItem]
        );

        // Second rule item group - users who checked out within the next 3 months.
        $today = new DateTime();
        $startDateDateRuleItem = new DateRuleItem();
        $startDateDateKey = new DateKey();
        $startDateDateKey->setName('checkoutdate');
        $startDateDateRuleItem->setKey($startDateDateKey);
        $startDateDateRuleItem->setOp(DateRuleItemDateOperator::AFTER);
        $startDateDateRuleItem->setValue($today->format('Ymd'));
        $startDateRuleItem = new RuleItem();
        $startDateRuleItem->setDateRuleItem($startDateDateRuleItem);

        $threeMonthsLater = new DateTime('+3 month');
        $endDateDateRuleItem = new DateRuleItem();
        $endDateDateKey = new DateKey();
        $endDateDateKey->setName('checkoutdate');
        $endDateDateRuleItem->setKey($endDateDateKey);
        $endDateDateRuleItem->setOp(DateRuleItemDateOperator::BEFORE);
        $endDateDateRuleItem->setValue($threeMonthsLater->format('Ymd'));
        $endDateRuleItem = new RuleItem();
        $endDateRuleItem->setDateRuleItem($endDateDateRuleItem);

        // Combine the date rule items into a RuleItemGroup.
        $checkedOutDateRangeItemGroup = new RuleItemGroup();
        $checkedOutDateRangeItemGroup->setItems(
            [$startDateRuleItem, $endDateRuleItem]
        );

        // Combine the rule item groups into a Rule so AdWords knows how to apply
        // the rules.
        $rule = new Rule();
        $rule->setGroups(
            [$checkoutMultipleItemGroup, $checkedOutDateRangeItemGroup]
        );
        // ExpressionRuleUserLists can use either CNF or DNF for matching. CNF means
        // 'at least one item in each rule item group must match', and DNF means 'at
        // least one entire rule item group must match'. DateSpecificRuleUserList
        // only supports DNF. You can also omit the rule type altogether to default
        // to DNF.
        $rule->setRuleType(UserListRuleTypeEnumsEnum::DNF);

        return $rule;
    }
private static function createUserListRule()
    {
        // First rule item group - users who visited the checkout page and had more
        // than one item in their shopping cart.
        $checkoutStringRuleItem = new StringRuleItem();
        $checkoutStringKey = new StringKey();
        $checkoutStringKey->setName('ecomm_pagetype');
        $checkoutStringRuleItem->setKey($checkoutStringKey);
        $checkoutStringRuleItem->setOp(StringRuleItemStringOperator::EQUALS);
        $checkoutStringRuleItem->setValue('checkout');
        $checkoutRuleItem = new RuleItem();
        $checkoutRuleItem->setStringRuleItem($checkoutStringRuleItem);

        $cartSizeNumberRuleItem = new NumberRuleItem();
        $cartSizeNumberKey = new NumberKey();
        $cartSizeNumberKey->setName('cartsize');
        $cartSizeNumberRuleItem->setKey($cartSizeNumberKey);
        $cartSizeNumberRuleItem->setOp(NumberRuleItemNumberOperator::GREATER_THAN);
        $cartSizeNumberRuleItem->setValue(1.0);
        $cartSizeRuleItem = new RuleItem();
        $cartSizeRuleItem->setNumberRuleItem($cartSizeNumberRuleItem);

        // Combine the two rule items into a RuleItemGroup so AdWords will AND their
        // rules together.
        $checkoutMultipleItemGroup = new RuleItemGroup();
        $checkoutMultipleItemGroup->setItems(
            [$checkoutRuleItem, $cartSizeRuleItem]
        );

        // Second rule item group - users who checked out within the next 3 months.
        $today = new DateTime();
        $startDateDateRuleItem = new DateRuleItem();
        $startDateDateKey = new DateKey();
        $startDateDateKey->setName('checkoutdate');
        $startDateDateRuleItem->setKey($startDateDateKey);
        $startDateDateRuleItem->setOp(DateRuleItemDateOperator::AFTER);
        $startDateDateRuleItem->setValue($today->format('Ymd'));
        $startDateRuleItem = new RuleItem();
        $startDateRuleItem->setDateRuleItem($startDateDateRuleItem);

        $threeMonthsLater = new DateTime('+3 month');
        $endDateDateRuleItem = new DateRuleItem();
        $endDateDateKey = new DateKey();
        $endDateDateKey->setName('checkoutdate');
        $endDateDateRuleItem->setKey($endDateDateKey);
        $endDateDateRuleItem->setOp(DateRuleItemDateOperator::BEFORE);
        $endDateDateRuleItem->setValue($threeMonthsLater->format('Ymd'));
        $endDateRuleItem = new RuleItem();
        $endDateRuleItem->setDateRuleItem($endDateDateRuleItem);

        // Combine the date rule items into a RuleItemGroup.
        $checkedOutDateRangeItemGroup = new RuleItemGroup();
        $checkedOutDateRangeItemGroup->setItems(
            [$startDateRuleItem, $endDateRuleItem]
        );

        // Combine the rule item groups into a Rule so AdWords knows how to apply
        // the rules.
        $rule = new Rule();
        $rule->setGroups(
            [$checkoutMultipleItemGroup, $checkedOutDateRangeItemGroup]
        );
        // ExpressionRuleUserLists can use either CNF or DNF for matching. CNF means
        // 'at least one item in each rule item group must match', and DNF means 'at
        // least one entire rule item group must match'. DateSpecificRuleUserList
        // only supports DNF. You can also omit the rule type altogether to default
        // to DNF.
        $rule->setRuleType(UserListRuleTypeEnumsEnum::DNF);

        return $rule;
    }
private static function createUserListRule ( ) { // First rule item group - users who visited the checkout page and had more // than one item in their shopping cart. $ checkoutStringRuleItem = new StringRuleItem ( ) ; $ checkoutStringKey = new StringKey ( ) ; $ checkoutStringKey -> setName ( 'ecomm_pagetype' ) ; $ checkoutStringRuleItem -> setKey ( $ checkoutStringKey ) ; $ checkoutStringRuleItem -> setOp ( StringRuleItemStringOperator :: EQUALS ) ; $ checkoutStringRuleItem -> setValue ( 'checkout' ) ; $ checkoutRuleItem = new RuleItem ( ) ; $ checkoutRuleItem -> setStringRuleItem ( $ checkoutStringRuleItem ) ; $ cartSizeNumberRuleItem = new NumberRuleItem ( ) ; $ cartSizeNumberKey = new NumberKey ( ) ; $ cartSizeNumberKey -> setName ( 'cartsize' ) ; $ cartSizeNumberRuleItem -> setKey ( $ cartSizeNumberKey ) ; $ cartSizeNumberRuleItem -> setOp ( NumberRuleItemNumberOperator :: GREATER_THAN ) ; $ cartSizeNumberRuleItem -> setValue ( 1.0 ) ; $ cartSizeRuleItem = new RuleItem ( ) ; $ cartSizeRuleItem -> setNumberRuleItem ( $ cartSizeNumberRuleItem ) ; // Combine the two rule items into a RuleItemGroup so AdWords will AND their // rules together. $ checkoutMultipleItemGroup = new RuleItemGroup ( ) ; $ checkoutMultipleItemGroup -> setItems ( [ $ checkoutRuleItem , $ cartSizeRuleItem ] ) ; // Second rule item group - users who checked out within the next 3 months. $ today = new DateTime ( ) ; $ startDateDateRuleItem = new DateRuleItem ( ) ; $ startDateDateKey = new DateKey ( ) ; $ startDateDateKey -> setName ( 'checkoutdate' ) ; $ startDateDateRuleItem -> setKey ( $ startDateDateKey ) ; $ startDateDateRuleItem -> setOp ( DateRuleItemDateOperator :: AFTER ) ; $ startDateDateRuleItem -> setValue ( $ today -> format ( 'Ymd' ) ) ; $ startDateRuleItem = new RuleItem ( ) ; $ startDateRuleItem -> setDateRuleItem ( $ startDateDateRuleItem ) ; $ threeMonthsLater = new DateTime ( '+3 month' ) ; $ endDateDateRuleItem = new DateRuleItem ( ) ; $ endDateDateKey = new DateKey ( ) ; $ endDateDateKey -> setName ( 'checkoutdate' ) ; $ endDateDateRuleItem -> setKey ( $ endDateDateKey ) ; $ endDateDateRuleItem -> setOp ( DateRuleItemDateOperator :: BEFORE ) ; $ endDateDateRuleItem -> setValue ( $ threeMonthsLater -> format ( 'Ymd' ) ) ; $ endDateRuleItem = new RuleItem ( ) ; $ endDateRuleItem -> setDateRuleItem ( $ endDateDateRuleItem ) ; // Combine the date rule items into a RuleItemGroup. $ checkedOutDateRangeItemGroup = new RuleItemGroup ( ) ; $ checkedOutDateRangeItemGroup -> setItems ( [ $ startDateRuleItem , $ endDateRuleItem ] ) ; // Combine the rule item groups into a Rule so AdWords knows how to apply // the rules. $ rule = new Rule ( ) ; $ rule -> setGroups ( [ $ checkoutMultipleItemGroup , $ checkedOutDateRangeItemGroup ] ) ; // ExpressionRuleUserLists can use either CNF or DNF for matching. CNF means // 'at least one item in each rule item group must match', and DNF means 'at // least one entire rule item group must match'. DateSpecificRuleUserList // only supports DNF. You can also omit the rule type altogether to default // to DNF. $ rule -> setRuleType ( UserListRuleTypeEnumsEnum :: DNF ) ; return $ rule ; }
Create a user list rule composed of two rule item groups.

@return Rule the created rule
Create a user list rule composed of two rule item groups .