function getDayofWeek(){

5,813 views
Skip to first unread message

OneStop Marketing

unread,
May 15, 2017, 5:08:55 AM5/15/17
to AdWords Scripts Forum
Ik heb volgende functie:

---------------------------------------------------------------------------------
function getDayofWeek(){
  var today = new Date();  
  //Returns a number 0-6. Sunday is 0, Monday is 1, etc.
  var dayOfWeek = today.getDay();  
  var maxBid = 0;
  var time = today;
  
  //Checks if it is a weekend
   if(dayOfWeek == 6 || dayOfWeek == 0){
     maxBid = 0.03;
   }
   else
     maxBid = 1.00;
  return maxBid;
}
---------------------------------------------------------------------------------

En wil graag door de week maximaal €1,00 bieden en in het weekend maximaal €0,03 bieden. Is bovenstaande functie goed geschreven?

Alvast bedankt voor jullie input :)

Met vriendelijke groet,
Thijs

Tyler Sidell (AdWords Scripts Team)

unread,
May 15, 2017, 9:34:52 AM5/15/17
to AdWords Scripts Forum
Hi Thijs,

Thank you for reaching out. We can only respond in English but please feel free to respond if you have any further questions. I took a look at your script and it is very well written. The only thing that I would suggest modifying is to add an entity selector depending on which entity you want to modify (for example: ad group/campaign).  You would also need to call a method that sets maxBid to the entity.  For instance, you can use either setCpa(), setCpc(), or setCpm() based on your particular needs.  

I've provided a sample of some of the aforementioned modifications.  Please let me know if you have any issues while running the script.

function getDayofWeek() {
   
var today = new Date();
   
//Returns a number 0-6. Sunday is 0, Monday is 1, etc.
   
var dayOfWeek = today.getDay();
   
var maxBid = 0;
   
var time = today;

   
//Checks if it is a weekend

   
if (dayOfWeek == 6 || dayOfWeek == 0) {

        maxBid
= 0.03;
   
} else
        maxBid
= 1.00;

   
var adGroupSelector = AdWordsApp.adGroups().get();
   
while (adGroupSelector.hasNext()) {
       
var ag = adGroupSelector.next();
        ag
.bidding().setCpa(maxBid);
   
}
   
return maxBid;
}

function main() {
    getDayofWeek
();
}

Thanks,
Tyler Sidell
AdWords Scripts Team

OneStop Marketing

unread,
May 15, 2017, 10:03:13 AM5/15/17
to AdWords Scripts Forum
Hello Tyler,

thanks for your quick reply.

Here is our whole script:
function main() {
 
var accountSelector = MccApp.accounts()
     
.withLimit(50);
 
// Process the account in parallel. The callback method is optional.
  accountSelector
.executeInParallel('updateProductGroupBidBasedOnAdGroup', null);
}

function updateProductGroupBidBasedOnAdGroup() {

 
var maxBid = getDayofWeek();

 
var productGroups = AdWordsApp.productGroups()
 
.withCondition("AdGroupName CONTAINS '.'")
 
.withCondition("CampaignName STARTS_WITH 'DA'")

 
.withCondition("CampaignStatus != REMOVED")

 
.withCondition("PartitionType != SUBDIVISION")
 
.withCondition("AdGroupStatus != REMOVED")

 
.get();
 
while (productGroups.hasNext()) {
   
var productGroup = productGroups.next();
   
var adGroupCpc = parseFloat(productGroup.getAdGroup().bidding().getCpc());
   
var adGroupCpcName = parseFloat(productGroup.getAdGroup().getName().substr(0,4));
   
if(adGroupCpcName != adGroupCpc)
      adGroupCpc
= adGroupCpcName;
   
if(adGroupCpc != productGroup.getMaxCpc()){
     
//checks max bid

     
if(adGroupCpcName > maxBid)
        adGroupCpc
= maxBid;
     
//checks min bid
     
else if(adGroupCpcName < 0.03)
        adGroupCpc
= 0.03;
      productGroup
.setMaxCpc(adGroupCpc);

   
}
 
}
}

function getDayofWeek(){
 
var today = new Date();  
 
//Returns a number 0-6. Sunday is 0, Monday is 1, etc.
 
var dayOfWeek = today.getDay();  
 
var maxBid = 0;
 
var time = today;
 
 
//Checks if it is a weekend

   
if(dayOfWeek == 0 || dayOfWeek == 6){
     maxBid
= 0.50;
   
}
   
else
     maxBid
= 1.2;
 
return maxBid;
}

With this script we want to bid different in the weekend. But my question is. Is following rule correct to bid in the weekend max 0.03 and from monday to friday with 1.00?
   if(dayOfWeek == 0 || dayOfWeek == 6){
     maxBid
= 0.50;
   
}
   
else
     maxBid
= 1.2;
 
return maxBid;

Best regards,
Thijs Kamp


Tyler Sidell (AdWords Scripts Team)

unread,
May 15, 2017, 10:12:30 AM5/15/17
to AdWords Scripts Forum
Hi Thijs,

Thanks for providing the full script.  To answer your question, the rule that you outlined is correct to change the max bid to 0.03 on the weekend and 1.00 Monday-Friday.  Just make sure to change the values to 0.03 and 1.00 respectively below:

if (dayOfWeek == 0 || dayOfWeek == 6) {

    maxBid
= 0.50;
} else
    maxBid
= 1.2;
return maxBid;

Please revert if you have any additional questions.

Thanks,
Tyler Sidell
AdWords Scripts Team

OneStop Marketing

unread,
May 16, 2017, 5:44:27 AM5/16/17
to AdWords Scripts Forum
Thanks Tyler for your reply.
We will wait till next week to see if the weekend bid isn't more than 0.03 :)

Best regards,
Thijs

OneStop Marketing

unread,
May 22, 2017, 1:19:43 AM5/22/17
to AdWords Scripts Forum
Goodmorning Tyler,

the script for the weekend didn't work this saturday and sunday.
The bid wasn't changed this weekend. 

What is wrong with the script below?

function main() {
  var accountSelector = MccApp.accounts()
      .withLimit(50);
  // Process the account in parallel. The callback method is optional.
  accountSelector.executeInParallel('updateProductGroupBidBasedOnAdGroup', null);
}

function updateProductGroupBidBasedOnAdGroup() {

  var maxBid = getDayofWeek();

  var productGroups = AdWordsApp.productGroups()
  .withCondition("AdGroupName CONTAINS '.'")
  .withCondition("CampaignName CONTAINS 'shopping'")
     maxBid = 0.11;
   }
   else
     maxBid = 1.00;
  return maxBid;
}

Hope to hear from you :)

Best regards,
Thijs

Anthony Madrigal

unread,
May 22, 2017, 9:36:23 AM5/22/17
to AdWords Scripts Forum
Hi Thijs,

Could you please provide me with your CID and script name through reply privately to author so that I can see why the bids were not changed?

Thanks,
Anthony
AdWords Scripts Team
Reply all
Reply to author
Forward
0 new messages