Send a JSON webhook payload on every redirect click. Connect GT Link Manager to any automation platform — Zapier, Make (Integromat), n8n, Pipedream, or your own custom endpoint. Build automated workflows triggered by link clicks: send Slack notifications, update spreadsheets, trigger email sequences, and more.
Requirements
- GT Link Manager 1.5+ installed and active
- A webhook URL from your automation platform (e.g., Zapier’s “Webhooks by Zapier” trigger, Make’s webhook module, or n8n’s webhook node)
Installation
- Add the snippet below to your theme’s
functions.phpor a site-specific plugin - Replace the webhook URL with your actual endpoint
- (Optional) Set a shared secret for HMAC payload verification
The Code
<?php
/**
* GT Link Manager - Webhook Notifications
*
* Sends a JSON payload to any webhook URL on every redirect click.
* Works with Zapier, Make (Integromat), n8n, Pipedream, or any custom endpoint.
*
* Setup:
* 1. Create a webhook in your automation tool (Zapier: "Webhooks by Zapier" trigger)
* 2. Set GTLM_WEBHOOK_URL to that webhook URL
* 3. (Optional) Set a secret for payload verification
*
* Payload includes: link data, target URL, referrer, user agent, timestamp.
*/
defined( 'ABSPATH' ) || exit;
// ── Configuration ────────────────────────────────────────────────────────────
define( 'GTLM_WEBHOOK_URL', 'https://hooks.zapier.com/hooks/catch/your-id' ); // Webhook endpoint
define( 'GTLM_WEBHOOK_SECRET', '' ); // Shared secret for HMAC signature (optional)
// ─────────────────────────────────────────────────────────────────────────────
add_action( 'gtlm_before_redirect', 'gtlm_webhook_send', 10, 4 );
/**
* Send a webhook payload on every redirect.
*
* @param array $link Link data.
* @param string $target_url Destination URL.
* @param int $status HTTP status code.
* @param array $headers Response headers.
*/
function gtlm_webhook_send( array $link, string $target_url, int $status, array $headers ): void {
if ( str_contains( GTLM_WEBHOOK_URL, 'your-id' ) ) {
return; // Not configured yet.
}
$payload = [
'event' => 'link_click',
'timestamp' => gmdate( 'c' ),
'site_url' => home_url(),
'link' => [
'id' => (int) $link['id'],
'name' => $link['name'] ?? '',
'slug' => $link['slug'] ?? '',
'short_url' => home_url( sanitize_text_field( $_SERVER['REQUEST_URI'] ?? '' ) ),
'target_url' => $target_url,
'redirect' => $status,
'category_id' => (int) ( $link['category_id'] ?? 0 ),
'tags' => $link['tags'] ?? '',
],
'visitor' => [
'referrer' => sanitize_text_field( $_SERVER['HTTP_REFERER'] ?? '' ),
'user_agent' => sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ?? '' ),
],
];
$body = wp_json_encode( $payload );
$request_headers = [
'Content-Type' => 'application/json',
];
// Add HMAC signature for payload verification if secret is set.
if ( ! empty( GTLM_WEBHOOK_SECRET ) ) {
$request_headers['X-GTLM-Signature'] = hash_hmac( 'sha256', $body, GTLM_WEBHOOK_SECRET );
}
wp_remote_post(
GTLM_WEBHOOK_URL,
[
'body' => $body,
'headers' => $request_headers,
'blocking' => false,
'timeout' => 2,
]
);
}
How It Works
- Hooks into
gtlm_before_redirectto fire on every redirect click - Sends a structured JSON payload with: event type, timestamp, site URL, full link data, and visitor info
- Link data includes: ID, name, slug, short URL, target URL, redirect status, category, and tags
- Visitor data includes: referrer and user agent
- Optionally signs the payload with HMAC-SHA256 via the
X-GTLM-Signatureheader for verification - Non-blocking request (
'blocking' => false) — no redirect delay
Configuration Notes
The GTLM_WEBHOOK_SECRET is optional but recommended for production use. When set, the payload is signed with HMAC-SHA256 and the signature is sent in the X-GTLM-Signature header. Your receiving endpoint can verify the signature to ensure the webhook is authentic.
To verify the signature on the receiving end, compute hash_hmac('sha256', $raw_body, $secret) and compare it to the header value.