Track redirect clicks via Simple Analytics’ Events API. This is the most straightforward analytics integration — no API keys needed, just your domain name. Server-side tracking that bypasses ad blockers and works without JavaScript.
Requirements
- GT Link Manager 1.5+ installed and active
- A Simple Analytics account
- Your domain registered in Simple Analytics
Installation
- Add the snippet below to your theme’s
functions.phpor a site-specific plugin - Replace
example.comwith the domain registered in Simple Analytics - No API key required — that’s it!
The Code
<?php
/**
* GT Link Manager - Simple Analytics Integration
*
* Tracks redirect clicks via Simple Analytics Events API.
* Server-side — no JavaScript needed, bypasses ad blockers.
*
* Setup:
* 1. Set GTLM_SA_HOSTNAME to the domain registered in Simple Analytics.
* 2. That's it. No API key needed for the events endpoint.
*
* Event name: "link_click"
* Metadata: link_name, link_slug, target_url, redirect_type
*
* @see https://docs.simpleanalytics.com/events
*/
defined( 'ABSPATH' ) || exit;
// ── Configuration ────────────────────────────────────────────────────────────
define( 'GTLM_SA_HOSTNAME', 'example.com' ); // Your domain in Simple Analytics
// ─────────────────────────────────────────────────────────────────────────────
add_action( 'gtlm_before_redirect', 'gtlm_sa_track_click', 10, 4 );
/**
* Send an event to Simple Analytics when a redirect fires.
*
* @param array $link Link data.
* @param string $target_url Destination URL.
* @param int $status HTTP status code.
* @param array $headers Response headers.
*/
function gtlm_sa_track_click( array $link, string $target_url, int $status, array $headers ): void {
if ( GTLM_SA_HOSTNAME === 'example.com' ) {
return; // Not configured yet.
}
$request_path = sanitize_text_field( $_SERVER['REQUEST_URI'] ?? '/' );
$payload = [
'type' => 'event',
'hostname' => GTLM_SA_HOSTNAME,
'event' => 'link_click',
'path' => $request_path,
'metadata' => [
'link_name' => $link['name'] ?? '',
'link_slug' => $link['slug'] ?? '',
'target_url' => $target_url,
'redirect_type' => (string) $status,
],
];
$forward_headers = [
'Content-Type' => 'application/json',
];
if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
$forward_headers['User-Agent'] = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
}
wp_remote_post(
'https://queue.simpleanalyticscdn.com/events',
[
'body' => wp_json_encode( $payload ),
'headers' => $forward_headers,
'blocking' => false,
'timeout' => 1,
]
);
}
How It Works
- Hooks into
gtlm_before_redirectto capture every redirect event - Sends a
link_clickevent to Simple Analytics’ queue endpoint - Forwards User-Agent for accurate device/browser detection
- Includes metadata: link_name, link_slug, target_url, and redirect_type
- Non-blocking request adds zero latency to the redirect
Configuration Notes
Events appear in your Simple Analytics dashboard under the Events tab. The event is named link_click and the metadata fields are available for filtering.
Simple Analytics is designed to be privacy-friendly and GDPR-compliant. No cookies are set, and no personal data is stored. This makes it an excellent choice if you need analytics without cookie consent banners.