Skip to content

Commit

Permalink
Changes for release v0_3. (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
fiboknacky authored Aug 31, 2018
1 parent 79f1910 commit 147bc76
Show file tree
Hide file tree
Showing 702 changed files with 31,527 additions and 10,950 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 0.3.0

* Added support and examples for V0_3 of Google Ads API.
* Updated GetArtifactMetadata to quote the name param value.
* Updated examples to initialize properties via constructors instead of
setters.
* Added examples showing how to add and get ad group bid modifiers.
* Added an example showing how to create and attach shared keyword sets.
* Added an example showing how to remove shared set criteria.
* Updated hotel ad group bid modifier example with v0_3 criteria changes.
* Added AddCampaignBidModifier example.

## 0.2.0

* Added support for V0_2 of Google Ads API, which includes the Percent CPC
Expand Down
11 changes: 9 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
"url": "https://github.com/googleads/google-ads-php",
"description": "Google Ads API client for PHP",
"require": {
"google/gax": "^0.32.0",
"google/gax": "^0.35.0",
"google/protobuf": "^3.4.0",
"php" : ">=5.5.9 || ^7.0",
"ext-grpc": "*",
"ulrichsg/getopt-php": "^3.0",
"react/http": "^0.8.3"
"react/http": "^0.8.3",
"monolog/monolog": "^1.23.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35 || ^5.7",
Expand All @@ -33,6 +34,12 @@
"GPBMetadata\\": "src/Google/Ads/GoogleAds/Util/Testing/metadata"
}
},
"autoload-dev": {
"psr-4": {
"Google\\": "src/Google/Ads/GoogleAds/Util/Testing/Google",
"GPBMetadata\\": "src/Google/Ads/GoogleAds/Util/Testing/metadata"
}
},
"authors": [
{
"name": "Google",
Expand Down
145 changes: 145 additions & 0 deletions examples/AdvancedOperations/AddAdGroupBidModifier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?php
/**
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Google\Ads\GoogleAds\Examples\AdvancedOperations;

require __DIR__ . '/../../vendor/autoload.php';

use GetOpt\GetOpt;
use Google\Ads\GoogleAds\Examples\Utils\ArgumentNames;
use Google\Ads\GoogleAds\Examples\Utils\ArgumentParser;
use Google\Ads\GoogleAds\Lib\GoogleAdsClient;
use Google\Ads\GoogleAds\Lib\GoogleAdsClientBuilder;
use Google\Ads\GoogleAds\Lib\GoogleAdsException;
use Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder;
use Google\Ads\GoogleAds\Util\ResourceNames;
use Google\Ads\GoogleAds\V0\Common\DeviceInfo;
use Google\Ads\GoogleAds\V0\Enums\DeviceEnum\Device;
use Google\Ads\GoogleAds\V0\Errors\GoogleAdsError;
use Google\Ads\GoogleAds\V0\Resources\AdGroupBidModifier;
use Google\Ads\GoogleAds\V0\Services\AdGroupBidModifierOperation;
use Google\ApiCore\ApiException;
use Google\Protobuf\DoubleValue;
use Google\Protobuf\StringValue;

/**
* This example demonstrates how to add an ad group bid modifier for mobile devices. To get ad
* group bid modifiers, see AdvancedOperations/GetAdGroupBidModifiers.php
*/
class AddAdGroupBidModifier
{
const CUSTOMER_ID = 'INSERT_CUSTOMER_ID_HERE';
const AD_GROUP_ID = 'INSERT_AD_GROUP_ID_HERE';
// Specify the bid modifier value here or the default specified below will be used.
const BID_MODIFIER_VALUE = 1.5;

public static function main()
{
// Either pass the required parameters for this example on the command line, or insert them
// into the constants above.
$options = (new ArgumentParser())->parseCommandArguments([
ArgumentNames::CUSTOMER_ID => GetOpt::REQUIRED_ARGUMENT,
ArgumentNames::AD_GROUP_ID => GetOpt::REQUIRED_ARGUMENT,
ArgumentNames::BID_MODIFIER_VALUE => GetOpt::OPTIONAL_ARGUMENT
]);

// Generate a refreshable OAuth2 credential for authentication.
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();

// Construct a Google Ads client configured from a properties file and the
// OAuth2 credentials above.
$googleAdsClient = (new GoogleAdsClientBuilder())->fromFile()
->withOAuth2Credential($oAuth2Credential)
->build();

try {
self::runExample(
$googleAdsClient,
$options[ArgumentNames::CUSTOMER_ID] ?: self::CUSTOMER_ID,
$options[ArgumentNames::AD_GROUP_ID] ?: self::AD_GROUP_ID,
$options[ArgumentNames::BID_MODIFIER_VALUE] ?: self::BID_MODIFIER_VALUE
);
} catch (GoogleAdsException $googleAdsException) {
printf(
"Request with ID '%s' has failed.%sGoogle Ads failure details:%s",
$googleAdsException->getRequestId(),
PHP_EOL,
PHP_EOL
);
foreach ($googleAdsException->getGoogleAdsFailure()->getErrors() as $error) {
/** @var GoogleAdsError $error */
printf(
"\t%s: %s%s",
$error->getErrorCode()->getErrorCode(),
$error->getMessage(),
PHP_EOL
);
}
} catch (ApiException $apiException) {
printf(
"ApiException was thrown with message '%s'.%s",
$apiException->getMessage(),
PHP_EOL
);
}
}

/**
* Runs the example.
*
* @param GoogleAdsClient $googleAdsClient the Google Ads API client
* @param int $customerId the client customer ID without hyphens
* @param int $adGroupId the ad group ID to add an ad group bid modifier to
* @param float $bidModifierValue the bid modifier value to set
*/
public static function runExample(
GoogleAdsClient $googleAdsClient,
$customerId,
$adGroupId,
$bidModifierValue
) {
// Creates an ad group bid modifier for mobile devices with the specified ad group ID and
// bid modifier value.
$adGroupBidModifier = new AdGroupBidModifier([
'ad_group' => new StringValue(
['value' => ResourceNames::forAdGroup($customerId, $adGroupId)]
),
'bid_modifier' => new DoubleValue(['value' => $bidModifierValue]),
'device' => new DeviceInfo(['type' => Device::MOBILE])
]);

// Creates an ad group bid modifier operation for creating an ad group bid modifier.
$adGroupBidModifierOperation = new AdGroupBidModifierOperation();
$adGroupBidModifierOperation->setCreate($adGroupBidModifier);

// Issues a mutate request to add the ad group bid modifier.
$adGroupBidModifierServiceClient = $googleAdsClient->getAdGroupBidModifierServiceClient();
$response = $adGroupBidModifierServiceClient->mutateAdGroupBidModifiers(
$customerId,
[$adGroupBidModifierOperation]
);

printf("Added %d ad group bid modifier:%s", $response->getResults()->count(), PHP_EOL);

foreach ($response->getResults() as $addedAdGroupBidModifier) {
/** @var AdGroupBidModifier $addedAdGroupBidModifier */
print $addedAdGroupBidModifier->getResourceName() . PHP_EOL;
}
}
}

AddAdGroupBidModifier::main();
114 changes: 46 additions & 68 deletions examples/AdvancedOperations/AddExpandedTextAdWithUpgradedUrls.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
use Google\Ads\GoogleAds\Lib\GoogleAdsClientBuilder;
use Google\Ads\GoogleAds\Lib\GoogleAdsException;
use Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder;
use Google\Ads\GoogleAds\V0\Common\Ad;
use Google\Ads\GoogleAds\V0\Common\CustomParameter;
use Google\Ads\GoogleAds\V0\Common\ExpandedTextAdInfo;
use Google\Ads\GoogleAds\V0\Enums\AdGroupAdStatusEnum_AdGroupAdStatus;
use Google\Ads\GoogleAds\V0\Enums\AdGroupAdStatusEnum\AdGroupAdStatus;
use Google\Ads\GoogleAds\V0\Errors\GoogleAdsError;
use Google\Ads\GoogleAds\V0\Resources\Ad;
use Google\Ads\GoogleAds\V0\Resources\AdGroupAd;
use Google\Ads\GoogleAds\V0\Services\AdGroupAdOperation;
use Google\Ads\GoogleAds\V0\Services\AdGroupServiceClient;
Expand Down Expand Up @@ -108,80 +108,58 @@ public static function runExample(
$adGroupId
) {
// Creates the expanded text ad info.
$expandedTextAdInfo = new ExpandedTextAdInfo();

$wrappedHeadlinePart1 = new StringValue();
$wrappedHeadlinePart1->setValue('Luxury Cruise to Mars');
$expandedTextAdInfo->setHeadlinePart1($wrappedHeadlinePart1);

$wrappedHeadlinePart2 = new StringValue();
$wrappedHeadlinePart2->setValue('Visit the Red Planet in style.');
$expandedTextAdInfo->setHeadlinePart2($wrappedHeadlinePart2);

$wrappedDescription = new StringValue();
$wrappedDescription->setValue('Low-gravity fun for everyone!');
$expandedTextAdInfo->setDescription($wrappedDescription);

// Sets the expanded text ad info on an Ad.
$ad = new Ad();
$ad->setExpandedTextAd($expandedTextAdInfo);
$expandedTextAdInfo = new ExpandedTextAdInfo([
'headline_part1' => new StringValue(['value' => 'Luxury Cruise to Mars']),
'headline_part2' => new StringValue(['value' => 'Visit the Red Planet in style.']),
'description' => new StringValue(['value' => 'Low-gravity fun for everyone!'])
]);

// Specifies a list of final URLs. This field cannot be set if URL field is set. This may
// be specified at ad and criterion levels.
$wrappedFinalUrl1 = new StringValue();
$wrappedFinalUrl1->setValue('http://www.example.com/cruise/space/');
$wrappedFinalUrl2 = new StringValue();
$wrappedFinalUrl2->setValue('http://www.example.com/locations/mars/');
$ad->setFinalUrls([$wrappedFinalUrl1, $wrappedFinalUrl2]);
$ad = new Ad([
// Sets the expanded text ad info on an Ad.
'expanded_text_ad' => $expandedTextAdInfo,
// Specifies a list of final URLs. This field cannot be set if URL field is set. This
// may be specified at ad and criterion levels.
'final_urls' => [
new StringValue(['value' => 'http://www.example.com/cruise/space/']),
new StringValue(['value' => 'http://www.example.com/locations/mars/'])
],
// Specifies a tracking URL for 3rd party tracking provider. You may specify one at
// customer, campaign, ad group, ad or criterion levels.
'tracking_url_template' => new StringValue(
['value' =>
'http://tracker.example.com/?season={_season}&promocode={_promocode}&u={lpurl}']
),
// Since your tracking URL has two custom parameters, provide their values too. This can
// be provided at campaign, ad group, ad or criterion levels.
'url_custom_parameters' => [
new CustomParameter([
'key' => new StringValue(['value' => 'season']),
'value' => new StringValue(['value' => 'christmas'])
]),
new CustomParameter([
'key' => new StringValue(['value' => 'promocode']),
'value' => new StringValue(['value' => 'NY123'])
])
]
]);

// Specifies a list of final mobile URLs. This field cannot be set if URL field is set, or
// finalUrls is unset. This may be specified at ad and criterion levels.
/*
$wrappedFinalMobileUrl1 = new StringValue();
$wrappedFinalMobileUrl1->setValue('http://mobile.example.com/cruise/space/');
$wrappedFinalMobileUrl2 = new StringValue();
$wrappedFinalMobileUrl2->setValue('http://mobile.example.com/locations/mars/');
$ad->setFinalMobileUrls([$wrappedFinalMobileUrl1, $wrappedFinalMobileUrl2]);
$ad->setFinalMobileUrls([
new StringValue(['value' => 'http://mobile.example.com/cruise/space/']),
new StringValue(['value' => 'http://mobile.example.com/locations/mars/'])
]);
*/

// Specifies a tracking URL for 3rd party tracking provider. You may specify one at
// customer, campaign, ad group, ad or criterion levels.
$wrappedTrackingUrlTemplate = new StringValue();
$wrappedTrackingUrlTemplate->setValue(
'http://tracker.example.com/?season={_season}&promocode={_promocode}&u={lpurl}'
);
$ad->setTrackingUrlTemplate($wrappedTrackingUrlTemplate);

// Since your tracking URL has two custom parameters, provide their values too. This can
// be provided at campaign, ad group, ad or criterion levels.
$wrappedCustomParamKey1 = new StringValue();
$wrappedCustomParamKey1->setValue('season');
$wrappedCustomParamValue1 = new StringValue();
$wrappedCustomParamValue1->setValue('christmas');
$customParam1 = new CustomParameter();
$customParam1->setKey($wrappedCustomParamKey1);
$customParam1->setValue($wrappedCustomParamValue1);

$wrappedCustomParamKey2 = new StringValue();
$wrappedCustomParamKey2->setValue('promocode');
$wrappedCustomParamValue2 = new StringValue();
$wrappedCustomParamValue2->setValue('NY123');
$customParam2 = new CustomParameter();
$customParam2->setKey($wrappedCustomParamKey2);
$customParam2->setValue($wrappedCustomParamValue2);

$ad->setUrlCustomParameters([$customParam1, $customParam2]);

// Creates an ad group ad to hold the above ad.
$adGroupAd = new AdGroupAd();

$adGroupResourceName = AdGroupServiceClient::adGroupName($customerId, $adGroupId);
$wrappedAdGroupResourceName = new StringValue();
$wrappedAdGroupResourceName->setValue($adGroupResourceName);
$adGroupAd->setAdGroup($wrappedAdGroupResourceName);

$adGroupAd->setStatus(AdGroupAdStatusEnum_AdGroupAdStatus::PAUSED);
$adGroupAd->setAd($ad);
$adGroupAd = new AdGroupAd([
'ad_group' => new StringValue(
['value' => AdGroupServiceClient::adGroupName($customerId, $adGroupId)]
),
'status' => AdGroupAdStatus::PAUSED,
'ad' => $ad
]);

// Creates an ad group ad operation and add it to the operations array.
$adGroupAdOperation = new AdGroupAdOperation();
Expand Down
Loading

0 comments on commit 147bc76

Please sign in to comment.