To best utilize the Google Ads platform, agencies often use scripts in order to automate tasks that would otherwise be both tedious and use up valuable time. This article will introduce our script for disabling Google Ads for out-of-stock products that will help you avoid wasting budget and energy drawing in traffic to out-of-stock products.
According to Google’s own research, 98% of global consumers they surveyed engage in online shopping, meaning that it should be a top priority to make sure your ads never become redundant. Our script can help by allowing you to pause ads when products go out of stock, saving time both for the team and your consumers. Let’s get into it!
Disable Google Ads for Out-of-Stock Products Script
/*
_ ___ _ _ _____ ___ _
/_\ / __| | | |_ _/ _ \ (_)___
/ _ \ (__| |_| | | || (_) || / _ \
/_/ \_\___|\___/ |_| \___(_)_\___/
*/
// Configuration Object
const config = {
includeCampaigns: '', // enter campaign name or leave blank
excludeCampaigns: '', // enter campaign name or leave blank
htmlElement: 'sold_out', // html element representing 'out of stock'
urlIdentifier: '/product/', // URL identifier for product pages
};
function main() {
let labelName = 'Paused – Out of Stock';
let label = AdsApp.labels().withCondition(`Name = "${labelName}"`).get().next();
if (!label) {
label = AdsApp.createLabel(labelName);
}
checkActiveAds(label);
checkPausedAds(label);
}
function checkActiveAds(label) {
let adIterator = AdsApp.ads()
.withCondition('Status = ENABLED')
.withCondition(`CampaignName CONTAINS_IGNORE_CASE "${config.includeCampaigns}"`)
.withCondition(`CampaignName DOES_NOT_CONTAIN_IGNORE_CASE "${config.excludeCampaigns}"`)
.withCondition(`AdGroupName CONTAINS "${config.urlIdentifier}"`)
.get();
while (adIterator.hasNext()) {
let ad = adIterator.next();
let url = ad.urls().getFinalUrl();
if (url.includes(config.urlIdentifier) && isProductOutOfStock(url)) {
ad.pause();
ad.applyLabel(label.getName());
}
}
}
function checkPausedAds(label) {
let adIterator = AdsApp.ads()
.withCondition('Status = PAUSED')
.withCondition(`LabelNames CONTAINS_ANY ["${label.getName()}"]`)
.get();
while (adIterator.hasNext()) {
let ad = adIterator.next();
let url = ad.urls().getFinalUrl();
if (!isProductOutOfStock(url)) {
ad.enable();
ad.removeLabel(label.getName());
}
}
}
function isProductOutOfStock(url) {
let htmlContent;
try {
htmlContent = UrlFetchApp.fetch(url).getContentText();
} catch (e) {
console.error('Failed to fetch the URL: ' + url, e);
return false;
}
return htmlContent.includes(config.htmlElement);
}
Want to automate Google Ads with custom scripts?
If you liked this script or would like a personalized one, we’re here to help! Our team of developers with experience in PPC can create custom scripts to automate any aspect of your Google Ads accounts. Schedule a discovery call to discuss how we can assist you in implementing automation scripts effectively.
How to Use Scripts in Google Ads
Google Ads scripts have proved to be a bit of a game changer when it comes to managing PPC campaigns and freeing up time and effort for the important stuff. Scripts can be used to generate reports, adjust bids and budgets, pause or enable campaigns based on specific conditions, analyze data, and even create and manage ads.
Here’s how it’s done:
First off, sign in to your account and head to “Tools & Settings” in the menu. Select “Scripts” to access a library of pre-made scripts or create your own. Then choose the script that suits your needs and set it up by defining the conditions you want it to follow. Simple!
What is the Script for Disabling Google Ads for Out-of-Stock Products?
The script for disabling Google Ads for out-of-stock products is designed to monitor your product inventory. It checks to see if any of the products you’re running ads for are out of stock. When it detects an out-of-stock product, it automatically pauses the corresponding ads.
Additionally, the script can send you notifications, either by email or through other channels, to alert you when a product becomes out of stock. This way, you can take immediate action to restock or remove the product from your ads.
By using this script, you can optimise your ad spend and provide a better experience to potential customers, resulting in a more efficient and profitable advertising strategy.
How Do Google Shopping & Google Ads Track Product Inventory?
Google Shopping and Google Ads track product inventory through the Google Merchant Center. When you set up your product feed in the Merchant Center, you can assign attributes to each product, including availability. This indicates whether a product is in stock, out of stock, or on backorder.
By regularly updating the availability attribute, either manually or through automated feeds, Google Ads can track the inventory status of your products. This information helps determine whether to show or pause ads for specific products based on their availability.
How Do Out-of-Stock Products Affect Google Ads?
Running Google Ads for out-of-stock products can have big implications for your advertising efforts. Perhaps the most obvious is that it leads to an inefficient allocation of the valuable ad budget, wasting funds on promoting products that are unavailable and therefore don’t bring in financial gains.
It can also have an impact on customer experience and satisfaction. Customers being led to products that are unavailable may cause your agency’s reputation to diminish over time.
Lastly, running Google Ads for an out-of-stock product may give competitors a chance to identify where you may be falling short and capitalise on it by offering alternative products. Hence, running our script to disable Google Ads for out-of-stock products automatically saves you stress across the board.
Why Should You Use the Script for Disabling Google Ads for Out-of-Stock Products?
So using the script for disabling Google Ads for out-of-stock products is essential to avoid running ads for products you can’t sell. Advertising unavailable items can have detrimental effects such as driving prospects to competitor sites, harming SEO rankings, creating customer dissatisfaction and ultimately leading to financial losses.
By utilising the script, you ensure that only ads for in-stock products are displayed, protecting your brand reputation, maintaining customer satisfaction, and optimising your ad spend. It’s essentially a proactive approach.
Don’t risk losing money and damaging your brand; use this script to keep your ads relevant and profitable!
When to Use the Script for Disabling Google Ads for Out-of-Stock Products
So, when does using our script for disabling Google Ads for out-of-stock products come in handy?
Here are some scenarios we thought of:
- Holiday seasons. During peak shopping periods like Black Friday, Christmas, or other holidays, inventory tends to fluctuate more rapidly, so using the script could save you a lot of time and effort.
- Sales periods. When running promotional campaigns with limited quantities, it’s essential to disable ads for sold-out items, as products will sell out faster and could lead to heightened customer dissatisfaction.
- Product launches. When launching new products, the script can be invaluable in managing inventory and preventing ads from displaying for items that are not yet available.
- Inventory fluctuations. Certain businesses that experience frequent inventory fluctuations, such as limited edition or seasonal items, can benefit from the script.
- Clearance or end-of-season sales. When clearing out inventory or offering end-of-season discounts, it’s crucial to ensure that ads are only shown for products that are still in stock.
Custom Automation Scripts by Acuto
At Acuto, we understand the power of automation in digital advertising. Our team of experts can develop custom scripts tailored to your specific needs, not just for Google Ads but also for various other platforms.
These automation scripts save your agency time and money, allowing you to focus more on strategic planning and execution.
To learn more about how Acuto can help you automate your digital advertising processes, visit our solutions page here. You can also contact us directly to discuss your specific requirements.
Key Takeaways
Lets recap:
- Disabling Google Ads for out-of-stock products can save your budget, maintain customer satisfaction, and protect your SEO.
- Use the provided script to automate the process of pausing ads for out-of-stock products in your Google Ads account.
- Regularly update the availability attribute in the Google Merchant Center to track product inventory and inform Google Ads about product availability.
- Using the script is crucial during holiday seasons, sales periods, product launches, and limited-time offers, as well as all year round, for making your job just that little bit easier. You’re welcome!