EXPERT TUTORIALS

Sending Slack Alerts From Your Google Ads Script

Published: October 9, 2024

blog-header-image

All of our free Google Ads Scripts utilise email for sending alerts. In this guide, we’ll show you how to set up a Slack Webhook so that you can send alerts to Slack channels instead.

Step 1: Create a slack application

The first step you will need to do is to create a slack application. You can do this by signing up to the Slack Developer Program.

Step 2: Create an incoming webhook

Once you’ve created your slack application, we’ll next need to activate incoming webhooks. You can use the sidebar to navigate to incoming webhooks and then click the activate button.

Next select add a new Webhook to workspace and choose a channel to assign this too. Make sure to copy the webhook url once create.


❗Do not share this webhook externally as anyone with the URL can send messages to the slack channel.

Step 3: Update your Google Ads Script code.

We’ll need to add some additional functions to our code in order to create and send a message to the webhook.

Creating a slack message

Firstly, we will define a function that creates our slack message. These are highly customisable, and the example below is a minimalist plain text example. You can use Slack’s Block Kit Builder to create more advanced message types.

This function takes 1 argument, your message and returns a formatted message block.


function createSlackMessage(message) {

  let m = {
    "blocks": [
		{
			"type": "section",
			"text": {
				"type": "plain_text",
				"text": message,
				"emoji": true
			}
		}
	]
  }
  
  return m

}

Sending your message

This is the final step in the process. We will define a function that uses our formatted message block and send this to our webhook. You will need to add your slack webhook we copied earlier to this function.


function sendSlackMessage(slackMessage) {

    const SLACK_URL = YOUR_SLACK_WEBHOOK_URL
    var options = {
        method: "POST",
        contentType: "application/json",
        payload: JSON.stringify(slackMessage),
    };
    UrlFetchApp.fetch(SLACK_URL, options);
}

…and that’s it! This guide should give you the basic building blocks for integrating slack into your Google Ads Scripts.

Share Article

Related Posts