Simple Analytics click tracking is the easiest integration in this course: no API key, just your domain name in the endpoint. GT Link Manager fires the event server-side on each redirect, ad blockers can’t interfere, and your link clicks appear as events alongside your page views.
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.
If you need more event metadata than Simple Analytics accepts, Plausible or Matomo give you richer payloads with the same server-side pattern.