AdWords Script to Pause Ads When your Prices aren’t Competitive

E-commerce websites are now vulnerable to price wars from competitors who want to gain more market share. When a competitor makes an aggressive price move,  one of the first steps you should take is to stop the marketing activity of the affected products/services, until you think about how your participation should look like. So, you avoid any wasted spend on price-driven users, who are the majority these days.

To help you in handling prices wars, we’ve written an AdWords script to pause or enable campaigns based on the price difference between you and your competitors. The script is linked to a spreadsheet that contains the competitor prices and your prices. Both prices data are fetched and updated automatically from the website. You don’t have to worry about updating them manually.

The script then pauses the campaign if the price difference between your product and competitors’ is greater than a specific threshold you determine. And vice verse, it enables paused campaigns if your prices return to be competitive.

Finally, the script sends an email with all the actions have been taken, which campaigns have been paused or enabled.

How to use the script?

1. Add your campaigns name to a Google sheet
The first step is you add a column in your spreadsheet and name it “Campaign Name” and then include your AdWords campaign names of the relevant products.
Let’s say, you have two campaigns, one is promoting the iPhone 7 and another is advertising Galaxy S8. You want to compare your prices to the market prices, and if your prices are 15% higher that the lowest price, you want to pause these products campaigns.

2. Fetch your Competitors Prices Automatically

Google sheets have a function that allows you to import any content from any website and extract a specific information to your sheet. The formula is IMPORTXML(); You can read more about it here.
In our case, we want to import the price of specific products from our competitor’s website (or price comparison websites) to Google sheets.
Visit your competitor or the price comparison website and inspect (right click, then select Inspect) the price elements on the product page.


This brings up the developer inspection window where we can inspect the HTML element for the price. Then copy the class or id name of the price.


Navigate to your spreadsheet and add a new column next to your campaign name and call it “Competitor price”.  We are going to use IMPORTXML function with a second argument to access the HTML element on any pages. The syntax of the formula is as below:

=IMPORTXML("The Page URL","The Xpath Query")

The XPath query is to look for an HTML element on the page.  In our example, we copied the class name which is “lowPrice”.


The output of the formula should return the price on the page. Do the exact step with other products.

3. Fetch your Prices Automatically

Add a new column to the sheet next to the “Competitor Price” Column and name it “My Price”.  Use the exact formula above IMPORTXML to retrieve the prices from your product pages. Make sure to add the relevant page URL and XPath query.

4. Add and Schedule your AdWords Script

Navigate to your AdWords account and copy the script source below. Make sure to add your spreadsheet URL that contains the prices.Also,  change the price threshold based on your needs. Price threshold is the maximum difference between your product prices and competitor prices. In the example below, it’s set to 0.15, this means when my prices are 15% greater than my competitors’ prices, the campaigns will be paused.

Finally, add your email address, so you can receive a summary of all modifications happened.

* Price War Script
* Version 1.0
* Created By: Ahmed Ali
function main() {

 var SPREADSHEET_URL = "Add Your Spreadsheet URL Here";
 var priceThreshold = 0.15; //Change it based on your needs
 var Notify_Me ="Add Your Email here"

 var spreadsheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
 var sheet = spreadsheet.getActiveSheet();
 var data = sheet.getRange("A:C").getValues();
 var campaignPaused = [];
 var campaignEnabled= [];

 for (i in data) {

 if (i == 0) {
 var [CampaignName, CompetitorPrice, MyPrice] = data[i];

 if (CampaignName == "") {

 else {
 var campaignIterator = AdWordsApp.campaigns().withCondition('Name = ' + CampaignName).get();
 var difference = (MyPrice - CompetitorPrice) / MyPrice;

 while (campaignIterator.hasNext()) {
 var campaign =;
 if (difference >= priceThreshold) {

 if (campaign.isEnabled() == true) {

 else if (difference < priceThreshold) {
 if (campaign.isPaused() == true) {

var pricePercent = priceThreshold * 100;

 if ((campaignPaused.length > 0) && (campaignEnabled.length > 0)) {
 'Price War Script',
 'The below campaigns have been paused, since your prices are '+pricePercent+'% greater than your competitors: \n\n'+campaignPaused+ ' \n\nAlso, the below campaigns have been enabled, since your prices are '+pricePercent+'% less than your competitors: \n\n'+campaignEnabled+'\n\nPlease visit this spreadsheet for more info: '

 else if ((campaignPaused.length > 0) && (campaignEnabled.length == 0)) {
 'Price War Script',
 'The below campaigns have been paused, since your prices are '+pricePercent+'% greater than your competitors: \n\n'+campaignPaused+ '\n\n\Please visit this spreadsheet for more info: '

 else if ((campaignPaused.length == 0) && (campaignEnabled.length > 0)) {
 'Price War Script',
 'The below campaigns have been enabled, since your prices are '+pricePercent+'% greater than your competitors: \n\n'+campaignEnabled+ '\n\n\Please visit this spreadsheet for more info: '

[Cover photo by PPC HERO]


Ahmed launched his first digital campaign in 2013 through participating in Google Online Marketing Challenge. He competed with over 12,000 students from 80 countries to win the first place in Africa & MENA region and one of the best five campaigns in the world. Today, he works as an Associate Digital Director at Keyade Middle East.


  1. Yang Jieyu

    Hi Ahmed,

    Thanks a lot for writing out this killer script.

    Wanted to check how you would go about tracking for discounts as well? For example, if my competitor uses a different class/id for discount prices, would I have to go in and check manually and update the XML path?

    Hope to hear from you soon.



    • Hi Jerry,

      Thanks for your comment.

      You can pull the discount class as well and multiply it to the price class. The result should be the price after discount.

      Let me know how it goes. Also, feel free to share the website URL through the “Contact Me” page 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *