Inheritance: extends AdsUser
Exemplo n.º 1
1
function AddTextAdsExample(AdWordsUser $user, $adGroupId)
{
    // Get the service, which loads the required classes.
    $adGroupAdService = $user->GetService('AdGroupAdService', ADWORDS_VERSION);
    $numAds = 5;
    $operations = array();
    for ($i = 0; $i < $numAds; $i++) {
        // Create text ad.
        $textAd = new TextAd();
        $textAd->headline = 'Cruise #' . uniqid();
        $textAd->description1 = 'Visit the Red Planet in style.';
        $textAd->description2 = 'Low-gravity fun for everyone!';
        $textAd->displayUrl = 'www.example.com';
        $textAd->finalUrls = array('http://www.example.com');
        // Create ad group ad.
        $adGroupAd = new AdGroupAd();
        $adGroupAd->adGroupId = $adGroupId;
        $adGroupAd->ad = $textAd;
        // Set additional settings (optional).
        $adGroupAd->status = 'PAUSED';
        // Create operation.
        $operation = new AdGroupAdOperation();
        $operation->operand = $adGroupAd;
        $operation->operator = 'ADD';
        $operations[] = $operation;
    }
    // Make the mutate request.
    $result = $adGroupAdService->mutate($operations);
    // Display results.
    foreach ($result->value as $adGroupAd) {
        printf("Text ad with headline '%s' and ID '%s' was added.\n", $adGroupAd->ad->headline, $adGroupAd->ad->id);
    }
}
Exemplo n.º 2
0
/**
 * 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
 * @param string $campaignId the ID of the campaign to get targeting criteria
 *     for
 */
function GetCampaignTargetingCriteriaExample(AdWordsUser $user, $campaignId)
{
    // Get the service, which loads the required classes.
    $campaignCriterionService = $user->GetService('CampaignCriterionService', ADWORDS_VERSION);
    // 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', 'POLYGON', 'PROXIMITY', 'PLATFORM'));
    // 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)) {
            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);
}
/**
 * Runs the example.
 * @param AdWordsUser $user the user to run the example with
 * @param int $campaignId the campaign to modify
 */
function addProductScopeExample(AdWordsUser $user, $campaignId)
{
    // Get the CampaignCriterionService, which loads the required classes.
    $campaignCriterionService = $user->GetService('CampaignCriterionService', ADWORDS_VERSION);
    $productScope = new ProductScope();
    // This set of dimensions is for demonstration purposes only. It would be
    // extremely unlikely that you want to include so many dimensions in your
    // product scope.
    $productScope->dimensions[] = new ProductBrand('Nexus');
    $productScope->dimensions[] = new ProductCanonicalCondition('NEW');
    $productScope->dimensions[] = new ProductCustomAttribute('CUSTOM_ATTRIBUTE_0', 'my attribute value');
    $productScope->dimensions[] = new ProductOfferId('book1');
    $productScope->dimensions[] = new ProductType('PRODUCT_TYPE_L1', 'Media');
    $productScope->dimensions[] = new ProductType('PRODUCT_TYPE_L2', 'Books');
    // The value for the bidding category is a fixed ID for the 'Luggage & Bags'
    // category. You can retrieve IDs for categories from the ConstantDataService.
    // See the 'GetProductCategoryTaxonomy' example for more details.
    $productScope->dimensions[] = new ProductBiddingCategory('BIDDING_CATEGORY_L1', '-5914235892932915235');
    $campaignCriterion = new CampaignCriterion();
    $campaignCriterion->campaignId = $campaignId;
    $campaignCriterion->criterion = $productScope;
    // Create operation.
    $operation = new CampaignCriterionOperation();
    $operation->operand = $campaignCriterion;
    $operation->operator = 'ADD';
    // Make the mutate request.
    $result = $campaignCriterionService->mutate(array($operation));
    printf("Created a ProductScope criterion with ID '%s'", $result->value[0]->criterion->id);
}
/**
 * Runs the example.
 * @param AdWordsUser $user the user to run the example with
 * @param string $filePath the path of the file to download the report to
 */
function DownloadCriteriaReportExample(AdWordsUser $user, $filePath)
{
    // Load the service, so that the required classes are available.
    $user->LoadService('ReportDefinitionService', ADWORDS_VERSION);
    // Create selector.
    $selector = new Selector();
    $selector->fields = array('CampaignId', 'AdGroupId', 'Id', 'Criteria', 'CriteriaType', 'Impressions', 'Clicks', 'Cost');
    // Optional: use predicate to filter out paused criteria.
    $selector->predicates[] = new Predicate('Status', 'NOT_IN', array('PAUSED'));
    // Create report definition.
    $reportDefinition = new ReportDefinition();
    $reportDefinition->selector = $selector;
    $reportDefinition->reportName = 'Criteria performance report #' . uniqid();
    $reportDefinition->dateRangeType = 'LAST_7_DAYS';
    $reportDefinition->reportType = 'CRITERIA_PERFORMANCE_REPORT';
    $reportDefinition->downloadFormat = 'CSV';
    // Exclude criteria that haven't recieved any impressions over the date range.
    $reportDefinition->includeZeroImpressions = false;
    // Set additional options.
    $options = array('version' => ADWORDS_VERSION);
    // Optional: Set skipReportHeader, skipColumnHeader, skipReportSummary to
    //     suppress headers or summary rows.
    // $options['skipReportHeader'] = true;
    // $options['skipColumnHeader'] = true;
    // $options['skipReportSummary'] = true;
    // Optional: Set includeZeroImpressions to include zero impression rows in
    //     the report output.
    // $options['includeZeroImpressions'] = true;
    // Download report.
    ReportUtils::DownloadReport($reportDefinition, $filePath, $user, $options);
    printf("Report with name '%s' was downloaded to '%s'.\n", $reportDefinition->reportName, $filePath);
}
Exemplo n.º 6
0
/**
 * Runs the example.
 * @param AdWordsUser $user the user to run the example with
 * @param string $adGroupId the id of the parent ad group
 */
function GetTextAdsExample(AdWordsUser $user, $adGroupId)
{
    // Get the service, which loads the required classes.
    $adGroupAdService = $user->GetService('AdGroupAdService', ADWORDS_VERSION);
    // Create selector.
    $selector = new Selector();
    $selector->fields = array('Headline', 'Id');
    $selector->ordering[] = new OrderBy('Headline', 'ASCENDING');
    // Create predicates.
    $selector->predicates[] = new Predicate('AdGroupId', 'IN', array($adGroupId));
    $selector->predicates[] = new Predicate('AdType', 'IN', array('TEXT_AD'));
    // By default disabled ads aren't returned by the selector. To return them
    // include the DISABLED status in a predicate.
    $selector->predicates[] = new Predicate('Status', 'IN', array('ENABLED', 'PAUSED', 'DISABLED'));
    // Create paging controls.
    $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
    do {
        // Make the get request.
        $page = $adGroupAdService->get($selector);
        // Display results.
        if (isset($page->entries)) {
            foreach ($page->entries as $adGroupAd) {
                printf("Text ad with headline '%s' and ID '%s' was found.\n", $adGroupAd->ad->headline, $adGroupAd->ad->id);
            }
        } else {
            print "No text ads 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 GetExpressBusinessesExample(AdWordsUser $user)
{
    // Get the service, which loads the required classes.
    $businessService = $user->GetService('ExpressBusinessService', ADWORDS_VERSION);
    // Create selector.
    $selector = new Selector();
    $selector->fields = array('Id', 'Name', 'Website', 'Address', 'GeoPoint', 'Status');
    $selector->ordering[] = new OrderBy('Name', 'ASCENDING');
    // Create paging controls.
    $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
    do {
        // Make the get request.
        $page = $businessService->get($selector);
        // Display results.
        if (isset($page->entries)) {
            foreach ($page->entries as $business) {
                $address = $business->address !== NULL ? $business->address : new Address();
                $geoPoint = $business->geoPoint;
                printf("Express business found with name '%s' id %s website: %s " . "address: %s,%s,%s,%s,%s geo point: %d,%d status: %s\n", $business->name, $business->id, $business->website, $address->streetAddress, $address->streetAddress2, $address->cityName, $address->provinceName, $address->postalCode, $geoPoint->latitudeInMicroDegrees, $geoPoint->longitudeInMicroDegrees, $business->status);
            }
        } else {
            print "No express businesses 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 AddConversionTrackerExample(AdWordsUser $user)
{
    // Get the service, which loads the required classes.
    $conversionTrackerService = $user->GetService('ConversionTrackerService', ADWORDS_VERSION);
    // Create conversion tracker.
    $conversionTracker = new AdWordsConversionTracker();
    $conversionTracker->name = 'Interplanetary Cruise Conversion #' . uniqid();
    // Set additional settings (optional).
    $conversionTracker->status = 'ENABLED';
    $conversionTracker->category = 'DEFAULT';
    $conversionTracker->viewthroughLookbackWindow = 15;
    $conversionTracker->isProductAdsChargeable = TRUE;
    $conversionTracker->productAdsChargeableConversionWindow = 15;
    $conversionTracker->markupLanguage = 'HTML';
    $conversionTracker->textFormat = 'HIDDEN';
    $conversionTracker->conversionPageLanguage = 'en';
    $conversionTracker->backgroundColor = '#0000FF';
    // Create operation.
    $operation = new ConversionTrackerOperation();
    $operation->operand = $conversionTracker;
    $operation->operator = 'ADD';
    $operations = array($operation);
    // Make the mutate request.
    $result = $conversionTrackerService->mutate($operations);
    // Display result.
    $conversionTracker = $result->value[0];
    printf("Conversion type with name '%s' and ID '%.0f' was added.\n", $conversionTracker->name, $conversionTracker->id);
    printf("Tag code:\n%s\n", $conversionTracker->snippet);
}
/**
 * Runs the example.
 * @param AdWordsUser $user the user to run the example with
 */
function LookupLocationExample(AdWordsUser $user)
{
    // Get the service, which loads the required classes.
    $locationCriterionService = $user->GetService('LocationCriterionService', 'v201109');
    // Location names to look up.
    $locationNames = array('Paris', 'Quebec', 'Spain', 'Deutschland');
    // Locale to retrieve location names in.
    $locale = 'en';
    $selector = new Selector();
    $selector->fields = array('Id', 'LocationName', 'CanonicalName', 'DisplayType', 'ParentLocations', 'Reach');
    // Location names must match exactly, only EQUALS and IN are supported.
    $selector->predicates[] = new Predicate('LocationName', 'IN', $locationNames);
    // Only one locale can be used in a request.
    $selector->predicates[] = new Predicate('Locale', 'EQUALS', $locale);
    // Make the get request.
    $locationCriteria = $locationCriterionService->get($selector);
    // Display results.
    if (isset($locationCriteria)) {
        foreach ($locationCriteria as $locationCriterion) {
            if (isset($locationCriterion->location->parentLocations)) {
                $parentLocations = implode(', ', array_map('GetLocationString', $locationCriterion->location->parentLocations));
            } else {
                $parentLocations = 'N/A';
            }
            printf("The search term '%s' returned the location '%s' of type '%s' " . "with ID '%s', parent locations '%s', and reach '%d'.\n", $locationCriterion->searchTerm, $locationCriterion->location->locationName, $locationCriterion->location->displayType, $locationCriterion->location->id, $parentLocations, $locationCriterion->reach);
        }
    } else {
        print "No location criteria were found.\n";
    }
}
/**
 * Runs the example.
 * @param AdWordsUser $user the user to run the example with
 * @param string $campaignId the ID of the campaign to get stats for
 */
function GetCampaignStatsExample(AdWordsUser $user)
{
    // Get the service, which loads the required classes.
    $campaignService = $user->GetService('CampaignService', ADWORDS_VERSION);
    // Create selector.
    $selector = new Selector();
    $selector->fields = array('Id', 'Name', 'Impressions', 'Clicks', 'Cost', 'Ctr');
    $selector->predicates[] = new Predicate('Impressions', 'GREATER_THAN', array(0));
    // Set date range to request stats for.
    $dateRange = new DateRange();
    $dateRange->min = date('Ymd', strtotime('-1 week'));
    $dateRange->max = date('Ymd', strtotime('-1 day'));
    $selector->dateRange = $dateRange;
    // Create paging controls.
    $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
    do {
        // Make the get request.
        $page = $campaignService->get($selector);
        // Display results.
        if (isset($page->entries)) {
            foreach ($page->entries as $campaign) {
                printf("Campaign with name '%s' and id '%s' had the following stats " . "during the last week:\n", $campaign->name, $campaign->id);
                printf("  Impressions: %d\n", $campaign->campaignStats->impressions);
                printf("  Clicks: %d\n", $campaign->campaignStats->clicks);
                printf("  Cost: \$%.2f\n", $campaign->campaignStats->cost->microAmount / AdWordsConstants::MICROS_PER_DOLLAR);
                printf("  CTR: %.2f%%\n", $campaign->campaignStats->ctr * 100);
            }
        } else {
            print "No matching campaigns 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
 * @param string $labelId the label id to run the example with
 */
function GetCampaignsByLabelExample(AdWordsUser $user, $labelId)
{
    // Get the service, which loads the required classes.
    $campaignService = $user->GetService('CampaignService', ADWORDS_VERSION);
    // Create selector.
    $selector = new Selector();
    $selector->fields = array('Id', 'Name', 'Labels');
    // Labels filtering is performed by ID. You can use containsAny to select
    // campaigns with any of the label IDs, containsAll to select campaigns with
    // all of the label IDs, or containsNone to select campaigns with none of the
    // label IDs.
    $selector->predicates[] = new Predicate('Labels', 'CONTAINS_ANY', array($labelId));
    $selector->ordering[] = new OrderBy('Name', 'ASCENDING');
    // Create paging controls.
    $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
    do {
        // Make the get request.
        $page = $campaignService->get($selector);
        // Display results.
        if (isset($page->entries)) {
            foreach ($page->entries as $campaign) {
                printf("Campaign with name '%s' and ID '%d' and labels '%s'" . " was found.\n", $campaign->name, $campaign->id, implode(', ', array_map(function ($label) {
                    return sprintf('%d/%s', $label->id, $label->name);
                }, $campaign->labels)));
            }
        } else {
            print "No campaigns 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
 * @param string $campaignId the ID of the campaign to add the sitelinks to
 */
function UploadOfflineConversionsExample(AdWordsUser $user, $conversionName, $gClId, $conversionTime, $conversionValue)
{
    // Get the services, which loads the required classes.
    $conversionTrackerService = $user->GetService('ConversionTrackerService', ADWORDS_VERSION);
    $offlineConversionService = $user->GetService('OfflineConversionFeedService', ADWORDS_VERSION);
    // Create an upload conversion. Once created, this entry will be visible
    // under Tools and Analysis->Conversion and will have Source = "Import".
    $uploadConversion = new UploadConversion();
    $uploadConversion->category = 'PAGE_VIEW';
    $uploadConversion->name = $conversionName;
    $uploadConversion->viewthroughLookbackWindow = 30;
    $uploadConversion->ctcLookbackWindow = 90;
    $uploadConversionOperation = new ConversionTrackerOperation();
    $uploadConversionOperation->operator = 'ADD';
    $uploadConversionOperation->operand = $uploadConversion;
    $uploadConversionOperations = array($uploadConversionOperation);
    $result = $conversionTrackerService->mutate($uploadConversionOperations);
    $uploadConversion = $result->value[0];
    printf("New upload conversion type with name = '%s' and ID = %d was " . "created.\n", $uploadConversion->name, $uploadConversion->id);
    // Associate offline conversions with the upload conversion we created.
    $feed = new OfflineConversionFeed();
    $feed->conversionName = $conversionName;
    $feed->conversionTime = $conversionTime;
    $feed->conversionValue = $conversionValue;
    $feed->googleClickId = $gClId;
    $offlineConversionOperation = new OfflineConversionFeedOperation();
    $offlineConversionOperation->operator = 'ADD';
    $offlineConversionOperation->operand = $feed;
    $offlineConversionOperations = array($offlineConversionOperation);
    $result = $offlineConversionService->mutate($offlineConversionOperations);
    $feed = $result->value[0];
    printf('Uploaded offline conversion value of %d for Google Click ID = ' . "'%s' to '%s'.", $feed->conversionValue, $feed->googleClickId, $feed->conversionName);
}
/**
 * Runs the example.
 * @param AdWordsUser $user the user to run the example with
 */
function GetAllImagesAndVideosExample(AdWordsUser $user)
{
    // Get the service, which loads the required classes.
    $mediaService = $user->GetService('MediaService', ADWORDS_VERSION);
    // Create selector.
    $selector = new Selector();
    $selector->fields = array('MediaId', 'Width', 'Height', 'MimeType', 'Name');
    $selector->ordering = array(new OrderBy('MediaId', 'ASCENDING'));
    // Create predicates.
    $selector->predicates[] = new Predicate('Type', 'IN', array('IMAGE', 'VIDEO'));
    // Create paging controls.
    $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
    do {
        // Make the get request.
        $page = $mediaService->get($selector);
        // Display images.
        if (isset($page->entries)) {
            foreach ($page->entries as $media) {
                if ($media->MediaType == 'Image') {
                    $dimensions = MapUtils::GetMap($media->dimensions);
                    printf("Image with dimensions '%dx%d', MIME type '%s', and id '%s' " . "was found.\n", $dimensions['FULL']->width, $dimensions['FULL']->height, $media->mimeType, $media->mediaId);
                } else {
                    if ($media->MediaType == 'Video') {
                        printf("Video with name '%s' and id '%s' was found.\n", $media->name, $media->mediaId);
                    }
                }
            }
        } else {
            print "No images or videos 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
 * @param string $adId the id the ad to add the override to
 * @param string $campaignAdExtensionId the id of an existings campaign ad
 *     extension to override with
 */
function AddLocationExtensionOverrideExample(AdWordsUser $user, $adId, $campaignAdExtensionId)
{
    // Get the service, which loads the required classes.
    $adExtensionOverrideService = $user->GetService('AdExtensionOverrideService', ADWORDS_VERSION);
    // Create ad extenstion override.
    $adExtensionOverride = new AdExtensionOverride();
    $adExtensionOverride->adId = $adId;
    // Create ad extension using existing id.
    $adExtension = new AdExtension();
    $adExtension->id = $campaignAdExtensionId;
    $adExtensionOverride->adExtension = $adExtension;
    // Set override info (optional).
    $locationOverrideInfo = new LocationOverrideInfo();
    $locationOverrideInfo->radius = 5;
    $locationOverrideInfo->radiusUnits = 'MILES';
    $overrideInfo = new OverrideInfo();
    $overrideInfo->LocationOverrideInfo = $locationOverrideInfo;
    $adExtensionOverride->overrideInfo = $overrideInfo;
    // Create operations.
    $operation = new AdExtensionOverrideOperation();
    $operation->operand = $adExtensionOverride;
    $operation->operator = 'ADD';
    $operations = array($operation);
    // Make the mutate request.
    $result = $adExtensionOverrideService->mutate($operations);
    // Display results.
    if (isset($result->value)) {
        foreach ($result->value as $adExtensionOverride) {
            print 'Ad extension override with ad id "' . $adExtensionOverride->adId . '", ad extension id "' . $adExtensionOverride->adExtension->id . '", and type "' . $adExtensionOverride->adExtension->AdExtensionType . "\" was added.\n";
        }
    } else {
        print "No ad extension overrides were added.\n";
    }
}
/**
 * Runs the example.
 * @param AdWordsUser $user the user to run the example with
 */
function GetCampaignsExample(AdWordsUser $user)
{
    // Get the service, which loads the required classes.
    $campaignService = $user->GetService('CampaignService', ADWORDS_VERSION);
    // Create selector.
    $selector = new Selector();
    $selector->fields = array('Id', '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 = $campaignService->get($selector);
        // Display results.
        if (isset($page->entries)) {
            foreach ($page->entries as $campaign) {
                printf("Campaign with name '%s' and ID '%s' was found.\n", $campaign->name, $campaign->id);
            }
        } else {
            print "No campaigns 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 GetAdGroupBidModifiersExample(AdWordsUser $user)
{
    // Get the service, which loads the required classes.
    $bidModifierService = $user->GetService('AdGroupBidModifierService', ADWORDS_VERSION);
    // Create selector.
    $selector = new Selector();
    $selector->fields = array('CampaignId', 'AdGroupId', 'BidModifier', 'Id');
    $selector->ordering[] = new OrderBy('CampaignId', 'ASCENDING');
    // Create paging controls.
    $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
    do {
        // Make the get request.
        $page = $bidModifierService->get($selector);
        // Display results.
        if (isset($page->entries)) {
            foreach ($page->entries as $modifier) {
                $value = 'none';
                if (is_numeric($modifier->bidModifier)) {
                    $value = $modifier->bidModifier;
                }
                printf("Campaign ID %d, AdGroup ID %d, Criterion ID %d has ad group " . "level modifier: %s\n", $modifier->campaignId, $modifier->adGroupId, $modifier->criterion->id, $value);
            }
        } else {
            print "No bid modifiers 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
 * @param string $adGroupId the id of the parent ad group
 */
function GetPlacementsExample(AdWordsUser $user, $adGroupId)
{
    // Get the service, which loads the required classes.
    $adGroupCriterionService = $user->GetService('AdGroupCriterionService', ADWORDS_VERSION);
    // Create selector.
    $selector = new Selector();
    $selector->fields = array('PlacementUrl', 'Id');
    $selector->ordering[] = new OrderBy('PlacementUrl', 'ASCENDING');
    // Create predicates.
    $selector->predicates[] = new Predicate('AdGroupId', 'IN', array($adGroupId));
    $selector->predicates[] = new Predicate('CriteriaType', 'IN', array('PLACEMENT'));
    // Create paging controls.
    $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
    do {
        // Make the get request.
        $page = $adGroupCriterionService->get($selector);
        // Display results.
        if (isset($page->entries)) {
            foreach ($page->entries as $adGroupCriterion) {
                printf("Placement with URL '%s' and ID '%s' was found.\n", $adGroupCriterion->criterion->url, $adGroupCriterion->criterion->id);
            }
        } else {
            print "No placements 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 GetProductServicesExample(AdWordsUser $user, $productServiceSuggestion, $localeText)
{
    // Get the service, which loads the required classes.
    $productServiceService = $user->GetService('ProductServiceService', ADWORDS_VERSION);
    // Create selector.
    $selector = new Selector();
    $selector->fields = array('ProductServiceText');
    // Create predicates.
    $selector->predicates[] = new Predicate('ProductServiceText', 'EQUALS', array($productServiceSuggestion));
    $selector->predicates[] = new Predicate('Locale', 'EQUALS', array($localeText));
    // Create paging controls.
    $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
    do {
        // Make the get request.
        $page = $productServiceService->get($selector);
        // Display results.
        if (isset($page->entries)) {
            foreach ($page->entries as $productService) {
                printf("Product/service with text '%s' found\n", $productService->text);
            }
        } else {
            print "No products/services 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
 * @param string $campaignId the id of the campaign to add targeting criteria to
 */
function AddCampaignTargetingCriteriaExample(AdWordsUser $user, $campaignId)
{
    // Get the service, which loads the required classes.
    $campaignCriterionService = $user->GetService('CampaignCriterionService', ADWORDS_VERSION);
    $campaignCriteria = array();
    // Create locations. The IDs can be found in the documentation or retrieved
    // with the LocationCriterionService.
    $california = new Location();
    $california->id = 21137;
    $campaignCriteria[] = new CampaignCriterion($campaignId, null, $california);
    $mexico = new Location();
    $mexico->id = 2484;
    $campaignCriteria[] = new CampaignCriterion($campaignId, null, $mexico);
    // Create languages. The IDs can be found in the documentation or retrieved
    // with the ConstantDataService.
    $english = new Language();
    $english->id = 1000;
    $campaignCriteria[] = new CampaignCriterion($campaignId, null, $english);
    $spanish = new Language();
    $spanish->id = 1003;
    $campaignCriteria[] = new CampaignCriterion($campaignId, null, $spanish);
    // Create operations.
    $operations = array();
    foreach ($campaignCriteria as $campaignCriterion) {
        $operations[] = new CampaignCriterionOperation($campaignCriterion, 'ADD');
    }
    // Make the mutate request.
    $result = $campaignCriterionService->mutate($operations);
    // Display results.
    foreach ($result->value as $campaignCriterion) {
        printf("Campaign targeting criterion with ID '%s' and type '%s' was " . "added.\n", $campaignCriterion->criterion->id, $campaignCriterion->criterion->CriterionType);
    }
}
/**
 * Runs the example.
 * @param AdWordsUser $user the user to run the example with
 * @param string $adGroupId the parent ad group id of the ads to retrieve
 */
function GetAllDisapprovedAdsWithAwqlExample(AdWordsUser $user, $adGroupId)
{
    // Get the service, which loads the required classes.
    $adGroupAdService = $user->GetService('AdGroupAdService', ADWORDS_VERSION);
    // Create a query.
    $query = sprintf('SELECT Id, AdGroupAdDisapprovalReasons WHERE AdGroupId = ' . '%d AND AdGroupCreativeApprovalStatus = DISAPPROVED ORDER BY Id', $adGroupId);
    // Create paging controls.
    $offset = 0;
    do {
        $pageQuery = sprintf('%s LIMIT %d,%d', $query, $offset, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
        // Make the query request.
        $page = $adGroupAdService->query($pageQuery);
        // Display results.
        if (isset($page->entries)) {
            foreach ($page->entries as $adGroupAd) {
                printf("Ad with ID '%.0f', and type '%s' was disapproved for the " . "following reasons:\n", $adGroupAd->ad->id, $adGroupAd->ad->AdType);
                if (!empty($adGroupAd->disapprovalReasons)) {
                    foreach ($adGroupAd->disapprovalReasons as $reason) {
                        printf("\t'%s'\n", $reason);
                    }
                }
            }
        } else {
            print "No disapproved ads were found.\n";
        }
        // Advance the paging offset.
        $offset += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
    } while ($page->totalNumEntries > $offset);
}
/**
 * Runs the example.
 * @param AdWordsUser $user the user to run the example with
 * @param string $adGroupId the id of the parent ad group
 */
function GetKeywordsExample(AdWordsUser $user, $adGroupId)
{
    // Get the service, which loads the required classes.
    $adGroupCriterionService = $user->GetService('AdGroupCriterionService', 'v201109_1');
    // Create selector.
    $selector = new Selector();
    $selector->fields = array('KeywordText', 'KeywordMatchType', 'Id');
    $selector->ordering[] = new OrderBy('KeywordText', 'ASCENDING');
    // Create predicates.
    $selector->predicates[] = new Predicate('AdGroupId', 'IN', array($adGroupId));
    $selector->predicates[] = new Predicate('CriteriaType', 'IN', array('KEYWORD'));
    // Create paging controls.
    $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
    do {
        // Make the get request.
        $page = $adGroupCriterionService->get($selector);
        // Display results.
        if (isset($page->entries)) {
            foreach ($page->entries as $adGroupCriterion) {
                printf("Keyword with text '%s', match type '%s', and id '%s' was " . "found.\n", $adGroupCriterion->criterion->text, $adGroupCriterion->criterion->matchType, $adGroupCriterion->criterion->id);
            }
        } else {
            print "No keywords 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
 * @param string $adGroupId the ID of the ad group of the ad to upgrade
 * @param string $adId the ID of the ad to upgrade
 */
function UpgradeAdUrlExample(AdWordsUser $user, $adGroupId, $adId)
{
    // Get the service, which loads the required classes.
    $adGroupAdService = $user->GetService('AdGroupAdService', ADWORDS_VERSION);
    $adGroupAd = null;
    // Retrieving the ad first.
    $selector = new Selector();
    $selector->fields = array('Id', 'Url');
    $selector->ordering[] = new OrderBy('Headline', 'ASCENDING');
    // Restrict the fetch to only the selected ad group ID and ad ID.
    $selector->predicates[] = new Predicate('AdGroupId', 'EQUALS', array($adGroupId));
    $selector->predicates[] = new Predicate('Id', 'EQUALS', array($adId));
    $page = $adGroupAdService->get($selector);
    if (isset($page->entries)) {
        $adGroupAd = $page->entries[0];
        printf("About to upgrade ad ID %d with URL '%s'.\n", $adGroupAd->ad->id, $adGroupAd->ad->url);
    } else {
        print "Ad for upgrade was not found.\n";
        return;
    }
    // Proceed with URL upgrade.
    $upgradeUrl = new AdUrlUpgrade();
    $upgradeUrl->adId = $adGroupAd->ad->id;
    $upgradeUrl->finalUrl = $adGroupAd->ad->url;
    $result = $adGroupAdService->upgradeUrl(array($upgradeUrl));
    // Display results.
    foreach ($result as $adGroupAd) {
        printf("Text ad with ID %d was upgraded to final URLs: '%s'.\n", $adGroupAd->id, join(",", $adGroupAd->finalUrls));
    }
}
Exemplo n.º 23
0
/**
 * Runs the example.
 * @param AdWordsUser $user the user to run the example with
 * @param string $adGroupId the id of the ad group that contains the keyword
 * @param string $criterionId the id of the keyword
 */
function UpdateKeywordExample(AdWordsUser $user, $adGroupId, $criterionId)
{
    // Get the service, which loads the required classes.
    $adGroupCriterionService = $user->GetService('AdGroupCriterionService', ADWORDS_VERSION);
    // Create criterion using an existing ID. Use the base class Criterion
    // instead of Keyword to avoid having to set keyword-specific fields.
    $criterion = new Criterion();
    $criterion->id = $criterionId;
    // Create ad group criterion.
    $adGroupCriterion = new BiddableAdGroupCriterion();
    $adGroupCriterion->adGroupId = $adGroupId;
    $adGroupCriterion->criterion = new Criterion($criterionId);
    // Update destination URL.
    $adGroupCriterion->destinationUrl = 'http://www.example.com/new';
    // Create operation.
    $operation = new AdGroupCriterionOperation();
    $operation->operand = $adGroupCriterion;
    $operation->operator = 'SET';
    $operations = array($operation);
    // Make the mutate request.
    $result = $adGroupCriterionService->mutate($operations);
    // Display result.
    $adGroupCriterion = $result->value[0];
    printf("Keyword with ID '%s' has updated destination URL '%s'.\n", $adGroupCriterion->criterion->id, $adGroupCriterion->destinationUrl);
}
Exemplo n.º 24
0
/**
 * 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
 * @param string $campaignId the id of the campaign to modify
 * @param float $bidModifier the multiplier to set on the campaign
 */
function SetBidModifierExample(AdWordsUser $user, $campaignId, $bidModifier)
{
    // Get the CampaignCriterionService, also loads classes
    $campaignCriterionService = $user->GetService("CampaignCriterionService", ADWORDS_VERSION);
    // Create Mobile Platform. The ID can be found in the documentation.
    // https://developers.google.com/adwords/api/docs/appendix/platforms
    $mobile = new Platform();
    $mobile->id = 30001;
    // HighEndMobile = 30001
    // Create criterion with modified bid.
    $criterion = new CampaignCriterion();
    $criterion->campaignId = $campaignId;
    $criterion->criterion = $mobile;
    $criterion->bidModifier = $bidModifier;
    // Create SET operation.
    $operation = new CampaignCriterionOperation();
    $operation->operator = "SET";
    $operation->operand = $criterion;
    // Update campaign criteria.
    $results = $campaignCriterionService->mutate(array($operation));
    // Display campaign criteria.
    if (count($results->value)) {
        foreach ($results->value as $campaignCriterion) {
            printf("Campaign criterion with campaign ID '%s', criterion ID '%s', " . "and type '%s' was modified with bid %.2f.\n", $campaignCriterion->campaignId, $campaignCriterion->criterion->id, $campaignCriterion->criterion->type, $campaignCriterion->bidModifier);
        }
        return true;
    }
    print "No campaign criterias were modified.";
}
/**
 * Runs the example.
 * @param AdWordsUser $user the user to run the example with
 * @param string $adGroupId the parent ad group id of the ads to retrieve
 */
function GetAllDisapprovedAdsExample(AdWordsUser $user, $adGroupId)
{
    // Get the service, which loads the required classes.
    $adGroupAdService = $user->GetService('AdGroupAdService', ADWORDS_VERSION);
    // Create selector.
    $selector = new Selector();
    $selector->fields = array('Id', 'AdGroupAdDisapprovalReasons');
    $selector->ordering = array(new OrderBy('Id', 'ASCENDING'));
    // Create predicates.
    $selector->predicates[] = new Predicate('AdGroupId', 'IN', array($adGroupId));
    $selector->predicates[] = new Predicate('AdGroupCreativeApprovalStatus', 'IN', array('DISAPPROVED'));
    // Create paging controls.
    $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
    do {
        // Make the get request.
        $page = $adGroupAdService->get($selector);
        // Display results.
        if (isset($page->entries)) {
            foreach ($page->entries as $adGroupAd) {
                printf("Ad with ID '%.0f', and type '%s' was disapproved for the " . "following reasons:\n", $adGroupAd->ad->id, $adGroupAd->ad->AdType);
                if (!empty($adGroupAd->disapprovalReasons)) {
                    foreach ($adGroupAd->disapprovalReasons as $reason) {
                        printf("\t'%s'\n", $reason);
                    }
                }
            }
        } else {
            print "No disapproved ads 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 GetAccountAlertsExample(AdWordsUser $user)
{
    // Get the service, which loads the required classes.
    $alertService = $user->GetService('AlertService', ADWORDS_VERSION);
    // Create alert query.
    $alertQuery = new AlertQuery();
    $alertQuery->clientSpec = 'ALL';
    $alertQuery->filterSpec = 'ALL';
    $alertQuery->types = array('ACCOUNT_BUDGET_BURN_RATE', 'ACCOUNT_BUDGET_ENDING', 'ACCOUNT_ON_TARGET', 'CAMPAIGN_ENDED', 'CAMPAIGN_ENDING', 'CREDIT_CARD_EXPIRING', 'DECLINED_PAYMENT', 'MANAGER_LINK_PENDING', 'MISSING_BANK_REFERENCE_NUMBER', 'PAYMENT_NOT_ENTERED', 'TV_ACCOUNT_BUDGET_ENDING', 'TV_ACCOUNT_ON_TARGET', 'TV_ZERO_DAILY_SPENDING_LIMIT', 'USER_INVITE_ACCEPTED', 'USER_INVITE_PENDING', 'ZERO_DAILY_SPENDING_LIMIT');
    $alertQuery->severities = array('GREEN', 'YELLOW', 'RED');
    $alertQuery->triggerTimeSpec = 'ALL_TIME';
    // Create selector.
    $selector = new AlertSelector();
    $selector->query = $alertQuery;
    // Create paging controls.
    $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
    do {
        // Make the get request.
        $page = $alertService->get($selector);
        // Display results.
        if (isset($page->entries)) {
            foreach ($page->entries as $alert) {
                printf("Alert of type '%s' and severity '%s' for account '%d' was " . "found.\n", $alert->alertType, $alert->alertSeverity, $alert->clientCustomerId);
            }
        } else {
            print "No alerts 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 AddExpressBusinessesExample(AdWordsUser $user)
{
    // Get the service, which loads the required classes.
    $businessService = $user->GetService('ExpressBusinessService', ADWORDS_VERSION);
    $business1 = new ExpressBusiness();
    $business1->status = 'ENABLED';
    $business1->name = 'Express Interplanetary Cruise #' . uniqid();
    $business1->address = new Address('1600 Amphitheatre Pkwy', null, 'Mountain View', 'CA', null, null, 'US');
    $business1->website = 'http://www.example.com/cruise1';
    $business2 = new ExpressBusiness();
    $business2->status = 'ENABLED';
    $business2->name = 'Express Interplanetary Cruise #' . uniqid();
    $business2->address = new Address('1600 Amphitheatre Pkwy', null, 'Mountain View', 'CA', null, null, 'US');
    $business2->website = 'http://www.example.com/cruise2';
    $operations = array();
    $operation1 = new ExpressBusinessOperation();
    $operation1->operand = $business1;
    $operation1->operator = 'ADD';
    $operations[] = $operation1;
    $operation2 = new ExpressBusinessOperation();
    $operation2->operand = $business2;
    $operation2->operator = 'ADD';
    $operations[] = $operation2;
    $addedBusinesses = $businessService->mutate($operations);
    foreach ($addedBusinesses as $addedBusiness) {
        printf("Added express business with ID %d and name '%s'\n", $addedBusiness->id, $addedBusiness->name);
    }
}
Exemplo n.º 29
0
/**
 * Runs the example.
 * @param AdWordsUser $user the user to run the example with
 * @param string $adGroupId the id of the ad group containing the ad
 * @param string $adId the ID of the ad
 */
function PauseAdExample(AdWordsUser $user, $adGroupId, $adId)
{
    // Get the service, which loads the required classes.
    $adGroupAdService = $user->GetService('AdGroupAdService', ADWORDS_VERSION);
    // Create ad using an existing ID. Use the base class Ad instead of TextAd to
    // avoid having to set ad-specific fields.
    $ad = new Ad();
    $ad->id = $adId;
    // Create ad group ad.
    $adGroupAd = new AdGroupAd();
    $adGroupAd->adGroupId = $adGroupId;
    $adGroupAd->ad = $ad;
    // Update the status.
    $adGroupAd->status = 'PAUSED';
    // Create operation.
    $operation = new AdGroupAdOperation();
    $operation->operand = $adGroupAd;
    $operation->operator = 'SET';
    $operations = array($operation);
    // Make the mutate request.
    $result = $adGroupAdService->mutate($operations);
    // Display result.
    $adGroupAd = $result->value[0];
    printf("Ad of type '%s' with id '%s' has updated status '%s'.\n", $adGroupAd->ad->AdType, $adGroupAd->ad->id, $adGroupAd->status);
}
/**
 * Runs the example.
 * @param AdWordsUser $user the user to run the example with
 * @param string $campaignId the ID of the campaign to add the ad group to
 */
function AddAdGroupsExample(AdWordsUser $user, $campaignId)
{
    // Get the service, which loads the required classes.
    $adGroupService = $user->GetService('AdGroupService', ADWORDS_VERSION);
    $numAdGroups = 2;
    $operations = array();
    for ($i = 0; $i < $numAdGroups; $i++) {
        // Create ad group.
        $adGroup = new AdGroup();
        $adGroup->campaignId = $campaignId;
        $adGroup->name = 'Earth to Mars Cruise #' . uniqid();
        // Set bids (required).
        $bid = new CpmBid();
        $bid->bid = new Money(1000000);
        $biddingStrategyConfiguration = new BiddingStrategyConfiguration();
        $biddingStrategyConfiguration->bids[] = $bid;
        $adGroup->biddingStrategyConfiguration = $biddingStrategyConfiguration;
        // Set additional settings (optional).
        $adGroup->status = 'ENABLED';
        // Create operation.
        $operation = new AdGroupOperation();
        $operation->operand = $adGroup;
        $operation->operator = 'ADD';
        $operations[] = $operation;
    }
    // Make the mutate request.
    $result = $adGroupService->mutate($operations);
    // Display result.
    $adGroups = $result->value;
    foreach ($adGroups as $adGroup) {
        printf("Ad group with name '%s' and ID '%s' was added.\n", $adGroup->name, $adGroup->id);
    }
}