/** * Runs the example. * @param AdWordsUser $user the user to run the example with */ function AddPromotionExample(AdWordsUser $user, $businessId) { // Get the business service, which loads the required classes. $businessService = $user->GetService('ExpressBusinessService', ADWORDS_VERSION); // Get the business for the businessId. We will need its geo point // to create a Proximity criterion for the new Promotion. $businessSelector = new Selector(); $businessSelector->fields = array('Id', 'GeoPoint'); $businessPredicate = new Predicate('Id', 'EQUALS', array($businessId)); $businessSelector->predicates = array($businessPredicate); $businessEntries = $businessService->get($businessSelector)->entries; $business = $businessEntries[0]; // PromotionService requires the businessId on the user. $user->SetExpressBusinessId($businessId); // Get the promotion service. $promotionService = $user->GetService('PromotionService', ADWORDS_VERSION); // Set up the new Promotion. $marsTourPromotion = new Promotion(); $budget = new Money(); $budget->microAmount = 1000000; $marsTourPromotion->name = 'Mars Tour Promotion ' . uniqid(); $marsTourPromotion->status = 'PAUSED'; $marsTourPromotion->destinationUrl = 'http://www.example.com'; $marsTourPromotion->budget = $budget; $marsTourPromotion->callTrackingEnabled = true; // Criteria $criteria = array(); // Criterion - Travel Agency product service $productService = new ProductService(); $productService->text = 'Travel Agency'; $criteria[] = $productService; // Criterion - English language // The ID can be found in the documentation: // https://developers.google.com/adwords/api/docs/appendix/languagecodes $language = new Language(); $language->id = 1000; $criteria[] = $language; // Criterion - Within 15 miles $proximity = new Proximity(); $proximity->geoPoint = $business->geoPoint; $proximity->radiusDistanceUnits = 'MILES'; $proximity->radiusInUnits = 15; $criteria[] = $proximity; $marsTourPromotion->criteria = $criteria; // Creatives $creatives = array(); $creative1 = new Creative('Standard Mars Trip', 'Fly coach to Mars', 'Free in-flight pretzels'); $creatives[] = $creative1; $creative2 = new Creative('Deluxe Mars Trip', 'Fly first class to Mars', 'Unlimited powdered orange drink'); $creatives[] = $creative2; $marsTourPromotion->creatives = $creatives; $operations = array(); $operation = new PromotionOperation(); $operation->operand = $marsTourPromotion; $operation->operator = 'ADD'; $operations[] = $operation; $result = $promotionService->mutate($operations); $addedPromotion = $result[0]; printf("Added promotion ID %d with name '%s' to business ID %d\n", $addedPromotion->id, $addedPromotion->name, $businessId); }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with */ function GetPromotionsExample(AdWordsUser $user, $businessId) { $user->SetExpressBusinessId($businessId); // Get the service, which loads the required classes. $promotionService = $user->GetService('PromotionService', ADWORDS_VERSION); // Create selector. $selector = new Selector(); $selector->fields = array('PromotionId', 'Name'); $selector->ordering[] = new OrderBy('Name', 'ASCENDING'); // Create paging controls. $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE); do { // Make the get request. $page = $promotionService->get($selector); // Display results. if (isset($page->entries)) { foreach ($page->entries as $promotion) { printf("Express promotion found with name '%s' " . "id %s destinationUrl: %s\n", $promotion->name, $promotion->id, $promotion->destinationUrl); } } else { print "No express promotions were found.\n"; } // Advance the paging index. $selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE; } while ($page->totalNumEntries > $selector->paging->startIndex); }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with */ function AddPromotionExample(AdWordsUser $user, $businessId) { // PromotionService requires the businessId on the user. $user->SetExpressBusinessId($businessId); // Get the promotion service. $promotionService = $user->GetService('PromotionService', ADWORDS_VERSION); // Set up the new Promotion. $marsTourPromotion = new Promotion(); $budget = new Money(); $budget->microAmount = 1000000; $marsTourPromotion->name = 'Mars Tour Promotion ' . uniqid(); $marsTourPromotion->status = 'PAUSED'; $marsTourPromotion->destinationUrl = 'http://www.example.com'; $marsTourPromotion->budget = $budget; $marsTourPromotion->callTrackingEnabled = true; // Criteria $criteria = array(); // Criterion - Travel Agency product service $productService = new ProductService(); $productService->text = 'Travel Agency'; $criteria[] = $productService; // Criterion - English language // The ID can be found in the documentation: // https://developers.google.com/adwords/api/docs/appendix/languagecodes $language = new Language(); $language->id = 1000; $criteria[] = $language; // Criterion - City of California $location = new Location(); $location->id = 21137; $criteria[] = $location; $marsTourPromotion->criteria = $criteria; // Creatives $creatives = array(); $creative1 = new Creative('Standard Mars Trip', 'Fly coach to Mars', 'Free in-flight pretzels'); $creatives[] = $creative1; $creative2 = new Creative('Deluxe Mars Trip', 'Fly first class to Mars', 'Unlimited powdered orange drink'); $creatives[] = $creative2; $marsTourPromotion->creatives = $creatives; $operations = array(); $operation = new PromotionOperation(); $operation->operand = $marsTourPromotion; $operation->operator = 'ADD'; $operations[] = $operation; $result = $promotionService->mutate($operations); $addedPromotion = $result[0]; printf("Added promotion ID %d with name '%s' to business ID %d\n", $addedPromotion->id, $addedPromotion->name, $businessId); }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with */ function UpdatePromotionExample(AdWordsUser $user, $businessId, $promotionId) { // PromotionService requires the businessId on the user. $user->SetExpressBusinessId($businessId); // Get the service, which loads the required classes. $promotionService = $user->GetService('PromotionService', ADWORDS_VERSION); // Update the budget for the promotion. $promotion = new Promotion(); $promotion->id = $promotionId; $newBudget = new Money(); $newBudget->microAmount = 2000000; $promotion->budget = $newBudget; $operations = array(); $operation = new PromotionOperation(); $operation->operand = $promotion; $operation->operator = 'SET'; $operations[] = $operation; $result = $promotionService->mutate($operations); $mutatedPromotion = $result[0]; printf("Promotion ID %d for business ID %d now has budget micro amount %d\n", $mutatedPromotion->id, $businessId, $mutatedPromotion->budget->microAmount); }