Pause out of stock products with this Google Ads Script
Just in time for holiday shopping season, this script runs hourly and automatically pauses product ads that are out of stock on Shopify.
Black Friday and the busy holiday season is rapidly approaching, it’s a boom time for retailers, but with the fast-moving environment, products rapidly go out stock, often with ads still running resulting in wasted budget.
With large inventories, it’s almost impossible to keep on top of pausing ads to out of stock products manually.
We hated seeing retailers wasting paid media budget, so our team of developers built this Google Ads script that runs hourly and automatically pauses ads pointing to products that are out of stock on Shopify.
How does the script work?
The logic behind the script is quite simple. It follows the URLs of all active ads to the landing page and searches the landing page for a certain string of text, for example: “out of stock.”
If the product is out of stock then the ads are paused and the ads should then be labeled with “Paused – Out of Stock.”
The script also auto-enables ads that are back in stock. It reviews all ads that are labeled “Paused – Out of Stock” to see if the product is back in stock and if it is it will re-enable the ads.
It is worth noting that if you have a multi-variant product (sizes, for example) and your URL leads to an out of stock choice, this will be classified as an out of stock item.
How to configure the script
The script has a number of different options that you can configure depending on how you want to use it.
On line 16: Enter a common element of all of the campaigns that you want to include. If you want the script to work across all campaigns leave this blank. We would only suggest running this script on product level campaigns where ads point directly to a product page URL as opposed to a category page or other page on the website.
On line 19: Enter a common element of all of the campaigns that you want to exclude. If you want the script to work across all campaigns leave this blank.
On line 22 Enter the html element that you can find using inspect element detail on the page string. For example “sold_out.”
On line 25: Enter the part of the URL that identifies product pages. This is important otherwise the script will also scan category pages and if you have an out of stock product may pause all of the ads pointing towards the category which you will not want to do. For example, if your site is gymshark.com/products/gymshark-scrunchie-black then you would select enter /product/ as this is the common element for all product pages.
Once you’ve configured the script make sure that you test it to ensure that you’ve configured it correctly and the functionality is as expected.
Finally, you will need to set up the script on a schedule so that it runs hourly. It will then check all of your ads to ensure that they are not pointing towards any out of stock products and if they are pause them.