|
44 | 44 | use Microsoft\BingAds\V11\CampaignManagement\AdExtensionIdToEntityIdAssociation; |
45 | 45 | use Microsoft\BingAds\V11\CampaignManagement\AdExtensionStatus; |
46 | 46 | use Microsoft\BingAds\V11\CampaignManagement\AdExtensionsTypeFilter; |
47 | | -use Microsoft\BingAds\V11\CampaignManagement\AccountMigrationStatusesInfo; |
48 | | -use Microsoft\BingAds\V11\CampaignManagement\MigrationStatusInfo; |
49 | | -use Microsoft\BingAds\V11\CampaignManagement\MigrationStatus; |
50 | 47 | use Microsoft\BingAds\V11\CampaignManagement\Address; |
51 | 48 | use Microsoft\BingAds\V11\CampaignManagement\SiteLink; |
52 | 49 | use Microsoft\BingAds\V11\CampaignManagement\AssociationType; |
|
62 | 59 | use Microsoft\BingAds\Samples\V11\CampaignManagementHelper; |
63 | 60 | use Microsoft\BingAds\Samples\V11\CustomerManagementHelper; |
64 | 61 |
|
65 | | -$GLOBALS['SitelinkMigration'] = "SiteLinkAdExtension"; |
66 | 62 | $GLOBALS['AuthorizationData'] = null; |
67 | 63 | $GLOBALS['Proxy'] = null; |
68 | 64 | $GLOBALS['CustomerProxy'] = null; |
|
101 | 97 | $GLOBALS['CampaignProxy'] = new ServiceClient(ServiceClientType::CampaignManagementVersion11, $GLOBALS['AuthorizationData'], AuthHelper::GetApiEnvironment()); |
102 | 98 |
|
103 | 99 | date_default_timezone_set('UTC'); |
104 | | - |
105 | | - // To prepare for the sitelink ad extensions migration in 2017, you will need to determine |
106 | | - // whether the account has been migrated from SiteLinksAdExtension to Sitelink2AdExtension. |
107 | | - // All ad extension service operations available for both types of sitelinks; however you will |
108 | | - // need to determine which type to add, update, and retrieve. |
109 | | - |
110 | | - $sitelinkMigrationIsCompleted = false; |
111 | | - |
112 | | - // Optionally you can find out which pilot features the customer is able to use. Even if the customer |
113 | | - // is in pilot for sitelink migrations, the accounts that it contains might not be migrated. |
114 | | - $featurePilotFlags = CustomerManagementHelper::GetCustomerPilotFeatures($GLOBALS['AuthorizationData']->CustomerId)->FeaturePilotFlags->int; |
115 | | - |
116 | | - // The pilot flag value for Sitelink ad extension migration is 253. |
117 | | - // Pilot flags apply to all accounts within a given customer; however, |
118 | | - // each account goes through migration individually and has its own migration status. |
119 | | - if (in_array(253, $featurePilotFlags)) |
120 | | - { |
121 | | - // Account migration status below will be either NotStarted, InProgress, or Completed. |
122 | | - print("Customer is in pilot for Sitelink migration.\n\n"); |
123 | | - } |
124 | | - else |
125 | | - { |
126 | | - // Account migration status below will be NotInPilot. |
127 | | - print("Customer is not in pilot for Sitelink migration.\n\n"); |
128 | | - } |
129 | | - |
130 | | - // Even if you have multiple accounts per customer, each account will have its own |
131 | | - // migration status. This example checks the account provided above. |
132 | | - $accountMigrationStatusesInfos = CampaignManagementHelper::GetAccountMigrationStatuses( |
133 | | - array($GLOBALS['AuthorizationData']->AccountId), |
134 | | - $GLOBALS['SitelinkMigration'])->MigrationStatuses; |
135 | | - |
136 | | - foreach ($accountMigrationStatusesInfos->AccountMigrationStatusesInfo as $accountMigrationStatusesInfo) |
137 | | - { |
138 | | - CampaignManagementHelper::OutputAccountMigrationStatusesInfo($accountMigrationStatusesInfo); |
139 | | - |
140 | | - foreach ($accountMigrationStatusesInfo->MigrationStatusInfo->MigrationStatusInfo as $migrationStatusInfo) |
141 | | - { |
142 | | - if (($migrationStatusInfo->Status == MigrationStatus::Completed) && ($GLOBALS['SitelinkMigration'] == $migrationStatusInfo->MigrationType)) |
143 | | - { |
144 | | - $sitelinkMigrationIsCompleted = true; |
145 | | - } |
146 | | - } |
147 | | - } |
148 | | - |
| 100 | + |
149 | 101 | // Specify one or more campaigns. |
150 | 102 |
|
151 | 103 | $campaigns = array(); |
|
282 | 234 | $encodedExtension = new SoapVar($extension, SOAP_ENC_OBJECT, 'StructuredSnippetAdExtension', $GLOBALS['CampaignProxy']->GetNamespace()); |
283 | 235 | $adExtensions[] = $encodedExtension; |
284 | 236 |
|
285 | | - // Before migration only the deprecated SiteLinksAdExtension type can be added, |
286 | | - // and after migration only the new Sitelink2AdExtension type can be added. |
287 | | - if($sitelinkMigrationIsCompleted) |
| 237 | + foreach(GetSampleSitelink2AdExtensions() as $encodedExtension) |
288 | 238 | { |
289 | | - foreach(GetSampleSitelink2AdExtensions() as $encodedExtension) |
290 | | - { |
291 | | - $adExtensions[] = $encodedExtension; |
292 | | - } |
293 | | - } |
294 | | - else |
295 | | - { |
296 | | - foreach(GetSampleSiteLinksAdExtensions() as $encodedExtension) |
297 | | - { |
298 | | - $adExtensions[] = $encodedExtension; |
299 | | - } |
| 239 | + $adExtensions[] = $encodedExtension; |
300 | 240 | } |
301 | 241 |
|
302 | 242 | // Add all extensions to the account's ad extension library |
|
324 | 264 |
|
325 | 265 | for ($index = 0; $index < count($adExtensionIdentities->AdExtensionIdentity); $index++) |
326 | 266 | { |
327 | | - $adExtensionIdToEntityIdAssociations[$index] = new AdExtensionIdToEntityIdAssociation(); |
328 | | - $adExtensionIdToEntityIdAssociations[$index]->AdExtensionId = $adExtensionIdentities->AdExtensionIdentity[$index]->Id;; |
329 | | - $adExtensionIdToEntityIdAssociations[$index]->EntityId = $nillableCampaignIds[0]; |
330 | | - |
331 | | - $adExtensionIds[$index] = $adExtensionIdentities->AdExtensionIdentity[$index]->Id; |
| 267 | + if(!empty($adExtensionIdentities->AdExtensionIdentity[$index]) && isset($adExtensionIdentities->AdExtensionIdentity[$index]->Id)) |
| 268 | + { |
| 269 | + $adExtensionIdToEntityIdAssociations[$index] = new AdExtensionIdToEntityIdAssociation(); |
| 270 | + $adExtensionIdToEntityIdAssociations[$index]->AdExtensionId = $adExtensionIdentities->AdExtensionIdentity[$index]->Id;; |
| 271 | + $adExtensionIdToEntityIdAssociations[$index]->EntityId = $nillableCampaignIds[0]; |
| 272 | + |
| 273 | + $adExtensionIds[$index] = $adExtensionIdentities->AdExtensionIdentity[$index]->Id; |
| 274 | + } |
332 | 275 | }; |
333 | 276 |
|
334 | 277 | // Associate the specified ad extensions with the respective campaigns or ad groups. |
|
346 | 289 | $adExtensionIdToEntityIdAssociations, |
347 | 290 | AssociationType::Campaign |
348 | 291 | )->EditorialReasons; |
349 | | - |
350 | | - // If migration has been completed, then you should request the Sitelink2AdExtension objects. |
351 | | - // You can always request both types; however, before migration only the deprecated SiteLinksAdExtension |
352 | | - // type will be returned, and after migration only the new Sitelink2AdExtension type will be returned. |
| 292 | + |
353 | 293 | $adExtensionsTypeFilter = array( |
354 | | - $sitelinkMigrationIsCompleted ? AdExtensionsTypeFilter::Sitelink2AdExtension : AdExtensionsTypeFilter::SiteLinksAdExtension, |
355 | 294 | AdExtensionsTypeFilter::AppAdExtension, |
356 | 295 | AdExtensionsTypeFilter::CallAdExtension, |
357 | 296 | AdExtensionsTypeFilter::CalloutAdExtension, |
358 | 297 | AdExtensionsTypeFilter::ImageAdExtension, |
359 | 298 | AdExtensionsTypeFilter::LocationAdExtension, |
360 | 299 | AdExtensionsTypeFilter::ReviewAdExtension, |
361 | | - AdExtensionsTypeFilter::StructuredSnippetAdExtension, |
| 300 | + AdExtensionsTypeFilter::Sitelink2AdExtension, |
| 301 | + AdExtensionsTypeFilter::StructuredSnippetAdExtension, |
362 | 302 | ); |
363 | 303 |
|
364 | 304 | // Get the specified ad extensions from the account'ss ad extension library. |
|
579 | 519 | print $e->getTraceAsString()."\n\n"; |
580 | 520 | } |
581 | 521 | } |
582 | | - |
583 | | -function GetSampleSiteLinksAdExtensions() |
584 | | -{ |
585 | | - $adExtensions = array(); |
586 | | - |
587 | | - $extension = new SiteLinksAdExtension(); |
588 | | - $extension->SiteLinks = array(); |
589 | | - |
590 | | - for ($index = 0; $index < 2; $index++) |
591 | | - { |
592 | | - $extension->SiteLinks[$index] = new SiteLink(); |
593 | | - $extension->SiteLinks[$index]->Description1 = "Simple & Transparent."; |
594 | | - $extension->SiteLinks[$index]->Description2 = "No Upfront Cost."; |
595 | | - $extension->SiteLinks[$index]->DisplayText = "Women's Shoe Sale " . ($index+1); |
596 | | - |
597 | | - // Destination URLs are deprecated. |
598 | | - // If you are currently using the Destination URL, you must upgrade to Final URLs. |
599 | | - // Here is an example of a DestinationUrl you might have used previously. |
600 | | - // $extension->SiteLinks[$index]->DestinationUrl = "http://www.contoso.com/womenshoesale/?season=spring&promocode=PROMO123"; |
601 | | - |
602 | | - // To migrate from DestinationUrl to FinalUrls, you can set DestinationUrl |
603 | | - // to an empty string when updating the sitelink. If you are removing DestinationUrl, |
604 | | - // then FinalUrls is required. |
605 | | - // $extension->SiteLinks[$index]->DestinationUrl = ""; |
606 | | - |
607 | | - // With FinalUrls you can separate the tracking template, custom parameters, and |
608 | | - // landing page URLs. |
609 | | - |
610 | | - $extension->SiteLinks[$index]->FinalUrls = array(); |
611 | | - $extension->SiteLinks[$index]->FinalUrls[] = "http://www.contoso.com/womenshoesale"; |
612 | | - |
613 | | - // Final Mobile URLs can also be used if you want to direct the user to a different page |
614 | | - // for mobile devices. |
615 | | - $extension->SiteLinks[$index]->FinalMobileUrls = array(); |
616 | | - $extension->SiteLinks[$index]->FinalMobileUrls[] = "http://mobile.contoso.com/womenshoesale"; |
617 | | - |
618 | | - // You could use a tracking template which would override the campaign level |
619 | | - // tracking template. Tracking templates defined for lower level entities |
620 | | - // override those set for higher level entities. |
621 | | - // In this example we are using the campaign level tracking template. |
622 | | - $extension->SiteLinks[$index]->TrackingUrlTemplate = null; |
623 | | - |
624 | | - // Set custom parameters that are specific to this sitelink, |
625 | | - // and can be used by the sitelink, ad group, campaign, or account level tracking template. |
626 | | - // In this example we are using the campaign level tracking template. |
627 | | - $extension->SiteLinks[$index]->UrlCustomParameters = new CustomParameters(); |
628 | | - $extension->SiteLinks[$index]->UrlCustomParameters->Parameters = array(); |
629 | | - $customParameter1 = new CustomParameter(); |
630 | | - $customParameter1->Key = "promoCode"; |
631 | | - $customParameter1->Value = "PROMO" . ($index+1); |
632 | | - $extension->SiteLinks[$index]->UrlCustomParameters->Parameters[] = $customParameter1; |
633 | | - $customParameter2 = new CustomParameter(); |
634 | | - $customParameter2->Key = "season"; |
635 | | - $customParameter2->Value = "summer"; |
636 | | - $extension->SiteLinks[$index]->UrlCustomParameters->Parameters[] = $customParameter2; |
637 | | - } |
638 | | - |
639 | | - $encodedExtension = new SoapVar($extension, SOAP_ENC_OBJECT, 'SiteLinksAdExtension', $GLOBALS['CampaignProxy']->GetNamespace()); |
640 | | - $adExtensions[] = $encodedExtension; |
641 | | - |
642 | | - return $adExtensions; |
643 | | -} |
644 | 522 |
|
645 | 523 | function GetSampleSitelink2AdExtensions() |
646 | 524 | { |
@@ -701,7 +579,4 @@ function GetSampleSitelink2AdExtensions() |
701 | 579 | return $adExtensions; |
702 | 580 | } |
703 | 581 |
|
704 | | - |
705 | | - |
706 | | - |
707 | 582 | ?> |
0 commit comments