Call Only extensions Migration

362 views
Skip to first unread message

Michael Cloonan (AdWords API Team)

unread,
May 4, 2015, 1:57:29 PM5/4/15
to adwor...@googlegroups.com
Hello everyone. A few months ago, we announced the new CallOnlyAd as a replacement for the existing ONLY placeholder type.

We've had a lot of requests for an example of how this could be accomplished.

Here's an image of the web interface to help visualize how the old fields and extensions relate to the fields on the new ad type:



In addition, the following Java snippets can help you use the AdWords API to migrate to the new format. You can use this general flow in any of the client libraries; this is just a sample of what migration code might look like and how to map from the old information to the new information. Please note that these are only intended as a guideline and should be amended/extended to the needs and specifics of your platform. Please make sure to take care of additional campaign data (e.g. other extensions, labels). We also recommend to create the new campaigns in paused state and check the results of the migration before activating them/deleting the legacy ones.

// These mappings are taken from the placeholders reference page:

// https://developers.google.com/adwords/api/docs/appendix/placeholders#call

public static final int PHONE_NUMBER = 1;

public static final int COUNTRY_CODE = 2;

public static final int TRACKED = 3;

public static final int CONVERSION_TYPE_ID = 6;


// Let's assume the basic objects are there

AdWordsServices adWordsServices = ...;

AdWordsSession session = ...;

   

   

// It is up to you to determine the correct feed item for the call

// extension you want to migrate.

FeedItem feedItem = ...;


// This is the feed mapping that you are using for your call extensions.

FeedMapping mapping = ...;



// We need to make a temporary map to avoid repeatedly searching through

// the AttributeFieldMappings array.

Map<Long, Integer> placeholderIdMapping = new HashMap<Long, Integer>();

AttributeFieldMapping[] attributeFieldMappings =

   mapping.getAttributeFieldMappings();

for (int i = 0; i < attributeFieldMappings.length; i++){

 placeholderIdMapping.put(

     attributeFieldMappings[i].getFeedAttributeId(),

     attributeFieldMappings[i].getFieldId()

 );

}


// This map will map the placeholder ID to the value for this feed item.

// This will be useful later when populating the new ad.

Map<Integer, Object> placeholderValueMapping = new HashMap<Integer, Object>();

FeedItemAttributeValue[] attributes = feedItem.getAttributeValues();

for (int i = 0; i < attributes.length; i++){

 switch (placeholderIdMapping.get(attributes[i].getFeedAttributeId())) {

   case PHONE_NUMBER:

     placeholderValueMapping.put(PHONE_NUMBER,
                                 attributes[i].getStringValue());

     break;

   case COUNTRY_CODE:

     placeholderValueMapping.put(COUNTRY_CODE,
                                 attributes[i].getStringValue());

     break;

   case TRACKED:

     placeholderValueMapping.put(TRACKED,
                                 attributes[i].getBooleanValue());

     break;

   case CONVERSION_TYPE_ID:

     placeholderValueMapping.put(CONVERSION_TYPE_ID,
                                 attributes[i].getIntegerValue());

     break;

 }

}


// This is the previous text ad that you want to copy into your new

// CallOnlyAd.

TextAd previousAd = ...;


AdGroupAdServiceInterface adGroupAdService =

   adWordsServices.get(session, AdGroupAdServiceInterface.class);


CallOnlyAd ad = new CallOnlyAd();

ad.setDescription1(previousAd.getDescription1());

ad.setDescription2(previousAd.getDescription2());

ad.setDisplayUrl(previousAd.getDisplayUrl());

ad.setFinalUrls(previousAd.getFinalUrls());

ad.setCountryCode((String) placeholderValueMapping.get(COUNTRY_CODE));

ad.setPhoneNumber((String) placeholderValueMapping.get(PHONE_NUMBER));

ad.setBusinessName("Some name");

ad.setDisableCallConversion(!
    ((Boolean)placeholderValueMapping.get(TRACKED)));

ad.setConversionTypeId((Long)placeholderValueMapping.get(CONVERSION_TYPE_ID));

ad.setPhoneNumberVerificationUrl(previousAd.getDisplayUrl());


// It is up to you to determine the correct ad group where you want

// your new ad to reside.

AdGroupAd adGroupAd = new AdGroupAd();

adGroupAd.setAdGroupId(...);

adGroupAd.setAd(ad);


// Set up the operation to send to the API.

AdGroupAdOperation operation = new AdGroupAdOperation();

operation.setOperand(adGroupAd);

operation.setOperator(Operator.ADD);

AdGroupAdOperation[] operations = new AdGroupAdOperation[] {operation};


// Execute the operation and fetch the results.

AdGroupAdReturnValue result = adGroupAdService.mutate(operations);


All code made publicly available by a Google Developer Platforms engineer is licensed under the Apache 2 license unless otherwise noted. You may find a copy of this license at https://www.apache.org/licenses/LICENSE-2.0.html

After migrating the affected ads to the new “Call Only” format, please think about the next steps:
  • Pause or remove the original ads / feed items to avoid duplicate content
  • Amend your implementation for creating those ads in the future to use the new ad type

I hope this helps to ease the migration to the new CallOnlyAd!

Michael Cloonan, AdWords API Team
Reply all
Reply to author
Forward
0 new messages