Last active
February 15, 2017 10:04
-
-
Save vhsu/f252ab32f49c5328ba376dfdc37371c3 to your computer and use it in GitHub Desktop.
Create Mobile Ads Old Format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//----------------------------------- | |
// Create mobile preferred ads (use one with highest ctr) | |
// Ads a new Ad with a headline using the keyword with the most impressions | |
// Author : Vincent Hsu | |
// Website: http://www.suisseo.ch | |
// NB : This scipt is useless now since Mobile ads don't exist anymore, just storing stuff here | |
//----------------------------------- | |
function main() { | |
index = 0; | |
// minindex and maxindex are an easy way to bypass the 30 minutes limitation | |
minindex = 0; | |
maxindex = 20000; | |
// Let's start by getting all of the adGroups that are active | |
var ag_iter = AdWordsApp.adGroups() | |
.withCondition("Status = ENABLED") | |
.withCondition("CampaignStatus = ENABLED") | |
.withCondition("Clicks >= 10") | |
.forDateRange("LAST_30_DAYS") | |
.get(); | |
// Then we will go through each one | |
while (ag_iter.hasNext()) { | |
var ag = ag_iter.next(); | |
if (index++ >= minindex && index <= maxindex) { | |
var ad_iter = ag.ads() | |
.withCondition("Status = ENABLED") | |
.withCondition("AdGroupName DOES_NOT_CONTAIN_IGNORE_CASE 'bann'") | |
.withCondition("Type != MOBILE_AD") | |
.forDateRange("ALL_TIME") | |
.orderBy("Ctr DESC") | |
.get(); | |
var ad_array = new Array(); | |
while (ad_iter.hasNext()) { | |
ad_array.push(ad_iter.next()); | |
} | |
function trim(myString) { | |
return myString.replace(/^\s+/g, '').replace(/\s+$/g, '') | |
} | |
var optArgs = { | |
isMobilePreferred: true | |
}; | |
if (ad_array.length > 0) { | |
//if(ad_array[0].getDescription1().endsWith('.')){ description1 = ad_array[0].getDescription1()+ "" ;} | |
//else if(ad_array[0].getDescription1().length<35){ description1 = ad_array[0].getDescription1()+ "." ;} | |
ag.createTextAd( | |
ad_array[0].getHeadline(), | |
//toTitleCase(bestkword), | |
ad_array[0].getDescription1(), | |
ad_array[0].getDescription2(), | |
ad_array[0].getDisplayUrl().replace('www', 'm'), | |
// display url | |
ad_array[0].getDestinationUrl().replace('www', 'm'), | |
// destination url | |
optArgs) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment