AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Ads
4.3K members online now
4.3K members online now
Dive into advanced features like Remarketing, Flexible Bid Strategies, AdWords Editor, and AdWords Scripts
Guide Me
star_border
Reply

sales countdown Script error

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭
Hi all, 

I would really like to get my head around implementing successful scripts on Adwords campaigns, I have tried in the past but no such luck - however really want to crack it and would appreciate a bit of help - as the script I have tried to add has not worked, please can someone point out where Im going wrong I have attached the code below

var
END_DATE =newDate('December 23, 2013'); 
var AD_GROUP_NAME ='Christmas Sales'; 
 
function main(){ 
 
var timeLeft = calculateTimeLeftUntil(END_DATE); 
 
var adGroup = getAdGroup(AD_GROUP_NAME); 
 
var keywords = adGroup.keywords().get(); 
 
while(keywords.hasNext()){ 
   
var keyword = keywords.next(); 
   
// We want to update {param1} to use our calculated days and {param2} for hours. 
    keyword
.setAdParam(1, timeLeft['12 ']); 
    keyword
.setAdParam(2, timeLeft['9']); 
 
} 
} 

Many Thanks
1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Paul A
September 2015

Re: sales countdown Script error

Top Contributor
# 5
Top Contributor

Hi Paul, the script you have in your post before the last one works perfectly.  Try just copying and pasting that entire script back into your Account.

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits

View solution in original post

Re: sales countdown Script error

Collaborator ✭ ☆ ☆
# 2
Collaborator ✭ ☆ ☆

HI

I think what you have here is incomplete script the complete script is

// Date to use to find out how many days are remaining.
var END_DATE = new Date('December 21, 2012');
// Change this to the Ad Group you set up with text ads with AdParams.
var AD_GROUP_NAME = 'Widget Sale';

function main() {
  var timeLeft = calculateTimeLeftUntil(END_DATE);
  var adGroup = getAdGroup(AD_GROUP_NAME);
  var keywords = adGroup.keywords().get();
  while (keywords.hasNext()) {
    var keyword = keywords.next();
    // We want to update {param1} to use our calculated days and {param2} for hours.
    keyword.setAdParam(1, timeLeft['days']);
    keyword.setAdParam(2, timeLeft['hours']);
  }
}

var DAY_IN_MILLISECONDS = 1000*60*60*24;

function calculateTimeLeftUntil(end) {
  var current = new Date();
  var timeLeft = {};
  var daysFloat = (end - current) / (DAY_IN_MILLISECONDS);
  timeLeft['days'] = Math.floor(daysFloat);
  timeLeft['hours'] = Math.floor(24 * (daysFloat - timeLeft['days']));
  return timeLeft;
}

function getAdGroup(name) {
  var adGroupIterator = AdWordsApp.adGroups()
      .withCondition('Name = "' + name + '"')
      .withLimit(1)
      .get();
  if (adGroupIterator.hasNext()) {
    return adGroupIterator.next();
  }
}

 

And can be found at 

https://developers.google.com/adwords/scripts/docs/solutions/sale-countdown

Hope this helps

 

Regards, Nik
LinkedIn  |   @nikhilparachure | My Blog

Re: sales countdown Script error

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Thanks for this but I have entered it as

// Date to use to find out how many days are remaining.
var END_DATE = new Date('December 23, 2013');
// Change this to the Ad Group you set up with text ads with AdParams.
var AD_GROUP_NAME = 'Christmas Sales';

function main() {
var timeLeft = calculateTimeLeftUntil(END_DATE);
var adGroup = getAdGroup(AD_GROUP_NAME);
var keywords = adGroup.keywords().get();
while (keywords.hasNext()) {
var keyword = keywords.next();
// We want to update {param1} to use our calculated days and {param2} for hours.
keyword.setAdParam(1, timeLeft['days']);
keyword.setAdParam(2, timeLeft['hours']);
}
}

var DAY_IN_MILLISECONDS = 1000*60*60*24;

function calculateTimeLeftUntil(end) {
var current = new Date();
var timeLeft = {};
var daysFloat = (end - current) / (DAY_IN_MILLISECONDS);
timeLeft['days'] = Math.floor(daysFloat);
timeLeft['hours'] = Math.floor(24 * (daysFloat - timeLeft['days']));
return timeLeft;
}

function getAdGroup(name) {
var adGroupIterator = AdWordsApp.adGroups()
.withCondition('Name = "' + name + '"')
.withLimit(1)
.get();
if (adGroupIterator.hasNext()) {
return adGroupIterator.next();
}
}

 

But I get the error message "Missing ) after argument list. (line 7)" also which parts of the script am I supposed to amend? or do I even need to? Sorry but would really like to try and understand the scripts

Re: sales countdown Script error

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭
Sorry I have also added this part of the script

var DAY_IN_MILLISECONDS = 1000*60*60*24; function calculateTimeLeftUntil(end) { var current = new Date(); var timeLeft = {}; var daysFloat = (end - current) / (DAY_IN_MILLISECONDS); timeLeft['days'] = Math.floor(daysFloat); timeLeft['hours'] = Math.floor(24 * (daysFloat - timeLeft['days'])); return timeLeft; } function getAdGroup(name) { var adGroupIterator = AdWordsApp.adGroups() .withCondition('Name = "' + name + '"') .withLimit(1) .get(); if (adGroupIterator.hasNext()) { return adGroupIterator.next(); } }
Marked as Best Answer.
Solution
Accepted by topic author Paul A
September 2015

Re: sales countdown Script error

Top Contributor
# 5
Top Contributor

Hi Paul, the script you have in your post before the last one works perfectly.  Try just copying and pasting that entire script back into your Account.

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits

Re: sales countdown Script error

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭

Thank you this has worked perfectly