Skip to content
Gaurav TiwariDocs

How to Get a Slack Message When a Link Gets Clicked

Updated October 19, 2026

Some clicks deserve attention the moment they happen: a demo booking link, a high-ticket affiliate offer or the link in a partner’s newsletter on launch day. Checking a report the next morning is too late to react.

To get a Slack message when a link gets clicked, you tag those links in GT Link Manager and add a short must-use plugin. It posts to a Slack webhook each time a real visitor clicks a tagged link, after the visitor is already on their way.

GT Link Manager has no Slack setting of its own, but it fires a hook named gtlm_before_redirect on every redirect. That hook is all you need, either straight to Slack or through n8n, Zapier or Make when you want more steps.

I’d keep this to a handful of tagged links. A Slack message for every click on every link turns into noise within a day, and people start muting the channel.

Before You Start

  • A Slack workspace where you can add apps, or a workflow tool with a webhook trigger: n8n, Zapier or Make.
  • File access to your site, through SFTP or your host’s file manager, to add a file to wp-content/mu-plugins.
  • Links to watch. Any link works, and you’ll tag the ones that should notify.

Get a Webhook URL

You need one URL that accepts a POST request. Pick the route that fits:

  • Straight to Slack. Create a Slack app for your workspace, turn on Incoming Webhooks, click Add New Webhook to Workspace and choose a channel. Slack gives you a URL that starts with https://hooks.slack.com/services/. This is the simplest route, with one less service in the middle.
  • Through n8n, Zapier or Make. Start a workflow with a webhook trigger: the Webhook node in n8n, a Catch Hook in Webhooks by Zapier or a custom webhook in Make. Copy its URL, then add a Slack step that posts a message. Choose this route when you also want a sheet row, a CRM note or a filter by time of day.

Keep the URL private. Anyone who has it can post to your channel.

  1. Go to GT Links → All Links and click Edit on a link you want to watch.
  2. Add notify to Tags (comma-separated). Keep any tags already there.
  3. Click Save Link.
  4. Repeat for each link.

The tag is how the code below decides which clicks matter. Removing it stops the messages for that link, with no code change.

Add the Notification Code

  1. Create the folder wp-content/mu-plugins if it doesn’t exist.
  2. Create a file in it named gtlm-slack.php.
  3. Paste the code below and replace the webhook URL.
  4. Save the file. WordPress loads must-use plugins on its own, with nothing to activate.
<?php
/**
 * Plugin Name: GT Link Manager Slack Alerts
 * Description: Posts to Slack when a link tagged "notify" gets clicked.
 */

defined( 'ABSPATH' ) || exit;

const GTLM_SLACK_WEBHOOK = 'https://hooks.slack.com/services/XXX/YYY/ZZZ';
const GTLM_SLACK_TAG     = 'notify';

add_action( 'gtlm_before_redirect', function ( $link, $target_url ) {
	$tags = array_map( 'trim', explode( ',', strtolower( (string) ( $link['tags'] ?? '' ) ) ) );
	if ( ! in_array( GTLM_SLACK_TAG, $tags, true ) ) {
		return;
	}

	// Skip HEAD checks, logged-in editors and obvious bots.
	if ( 'GET' !== ( $_SERVER['REQUEST_METHOD'] ?? '' ) || current_user_can( 'edit_posts' ) ) {
		return;
	}
	$agent = strtolower( (string) ( $_SERVER['HTTP_USER_AGENT'] ?? '' ) );
	if ( '' === $agent || preg_match( '/bot|crawl|spider|slurp|preview|monitor/', $agent ) ) {
		return;
	}

	$from = esc_url_raw( wp_unslash( $_SERVER['HTTP_REFERER'] ?? '' ) );
	$text = sprintf(
		'Clicked: %1$s (%2$s) from %3$s',
		$link['name'],
		$link['slug'],
		$from ? $from : 'an unknown page'
	);

	// Post to Slack after the visitor has been redirected.
	add_action( 'shutdown', function () use ( $text ) {
		if ( function_exists( 'fastcgi_finish_request' ) ) {
			fastcgi_finish_request();
		}
		wp_remote_post(
			GTLM_SLACK_WEBHOOK,
			array(
				'headers' => array( 'Content-Type' => 'application/json' ),
				'body'    => wp_json_encode( array( 'text' => $text ) ),
				'timeout' => 5,
			)
		);
	} );
}, 10, 2 );

The message reads like “Clicked: Demo booking (book-demo) from https://yoursite.com/pricing/”. For n8n, Zapier or Make, the same text field arrives in the trigger, and you can add more fields to the array if your workflow needs them.

Why the Code Waits for Shutdown

gtlm_before_redirect fires before GT Link Manager sends the redirect headers. Anything slow inside it, such as a request to Slack, makes the visitor stare at a blank tab until Slack answers.

The code only prepares the message inside the hook. The request to Slack runs at shutdown, after the redirect has been written. On PHP-FPM, which most hosts use, fastcgi_finish_request() closes the visitor’s connection first, so they never wait on Slack at all.

The GT Link Manager Webhook Notifications (Zapier, Make, n8n) reference has a fuller JSON payload, with an HMAC signature you can verify on the receiving end. Move its request into a shutdown callback like the one above before you use it.

Check It Works

  1. Log out, or open a private window, because the code skips logged-in editors.
  2. Click a tagged link from one of your posts.
  3. The message should appear in Slack within a few seconds.

To test the webhook on its own, without WordPress, run this with your URL:

curl -X POST -H "Content-Type: application/json" -d '{"text":"Test from the terminal"}' https://hooks.slack.com/services/XXX/YYY/ZZZ

Slack answers ok when the URL works.

When Messages Don’t Arrive

SymptomLikely causeFix
Nothing in SlackThe link isn’t tagged notify, or you were logged inCheck the tag, then test from a private window
curl test returns invalid_token or no_serviceThe webhook was removed or the URL is wrongCreate a new webhook and update the file
Messages for crawlersA bot with an unusual user agentAdd its name to the pattern in the code
Redirects feel slowThe host doesn’t run PHP-FPMKeep the request at shutdown and the timeout short
A PHP error after adding the fileA paste errorFix the file, or rename it to .txt to switch it off

What It Won’t Do

  • No sales data. A click is not a purchase. Commissions stay in your affiliate dashboard.
  • No perfect bot filter. The user-agent check stops the common crawlers, not every script.
  • No rate limit. A viral link sends a message per click. Remove the tag when a link takes off.
  • No visitor identity. The message shows the referring page, which the browser may leave out.

The same hook and shutdown pattern can send each click to GA4 as well, which How to Track Affiliate Clicks in GA4 walks through.

Share

Was this helpful?

Still stuck? Open a support ticket