=== SteClick Counter ===
Contributors: kasuga16
Donate link: https://www.paypal.me/kasuga16
Tags: click tracking, download tracking, pdf tracking, link counter, analytics
Requires at least: 6.3
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.0.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Lightweight click tracking for WordPress. Track any link or button by simply adding a prefix to your URLs.

== Description ==

SteClick Counter is a lightweight WordPress plugin that lets you track link clicks by doing just one thing:  
**adding a simple prefix to your existing URLs.**

No complex setup. No external analytics services. No external libraries.

To start tracking clicks, simply add the prefix **`/?tag=XXX&to=`** before the URL you want to track.  
The plugin logs the click and immediately redirects the visitor to the destination.

This makes SteClick Counter ideal for tracking:
- Download buttons
- PDF links
- Embedded content
- External links and call-to-action buttons

**Key Benefits:**
* **Simple Prefix System:** No configuration required. Just add **`/?tag=XXX&to=`** to any link and start tracking instantly.
* **Lightweight & Fast:** No external libraries, no extra HTTP requests, and no performance impact on your site.
* **Bot & fraudulent-count protection:** Filters out bots and automated requests using UA signature matching, header mismatch detection, and JS-execution verification.
* **Database Lean:** Uses the file system for logging instead of creating database tables.
* **Privacy-First:** No cookies and no third-party services, all tracking data stays on your own server.

== How It Works ==

To track a link, prepend the **`/?tag=XXX&to=`** prefix to the original URL.

**Original URL:**
*https://example.com/document.pdf*

**Tracked URL:**
*/?tag=doc-01&to=https://example.com/document.pdf*

---

### Tracking a download link (HTML example)

You can also track download buttons or links by modifying the `href` attribute.

**Original HTML:**
*&lt;a href="https://example.com/wp-content/uploads/sample.zip"&gt;Download ZIP file&lt;/a&gt;*

**Tracked HTML:**
*&lt;a href="/?tag=zip01&to=https://example.com/wp-content/uploads/sample.zip"&gt;Download ZIP file&lt;/a&gt;*

When a visitor clicks a tracked link, SteClick Counter records:
- The timestamp
- Your custom tag
- The destination URL
- The referrer (source page)

You can view all click statistics in **Settings → SteClick Counter**.

== Installation ==

- Upload via WordPress Dashboard:
 1. In your WordPress dashboard, go to 'Plugins' → 'Add New'.
 2. Search for "steclick counter" and click 'Install Now'.
 3. Click 'Activate' once the installation is complete.
 4. Start tracking by adding the **`/?tag=XXX&to=`** prefix to your links.
 5. View click counts in **Settings → SteClick Counter**.

- Manual Installation via FTP:
 1. Download the plugin's zip file and extract it.
 2. Connect to your server via FTP and navigate to the "wp-content/plugins/" directory.
 3. Upload the extracted "steclick-counter" folder to this directory.
 4. Go to 'Plugins' in your WordPress dashboard and activate the plugin.
 5. Start tracking by adding the **`/?tag=XXX&to=`** prefix to your links.
 6. View click counts in **Settings → SteClick Counter**.

== Screenshots ==

1. Admin dashboard showing click statistics grouped by tag.

== Changelog ==

= 1.0.4 =
* Added: Clicks are now only counted when the frontend link-rewriting script has actually run in the visitor's browser, filtering out non-JavaScript automated requests (crawlers, monitors, direct URL scanners) even when they present browser-like User-Agent strings.
* Fixed: Log writes now use exclusive file locking to prevent data loss from concurrent requests (e.g. traffic bursts from scanners) racing on the read-modify-write of the log file.
* Fixed: The log table header now stays fixed in place while scrolling through log entries, instead of scrolling away with the content.

= 1.0.3 =
* Added: Basic User-Agent based filtering to exclude common bots, crawlers, and link-preview services from click counts.

= 1.0.2 =
* Improved: Referrer is now captured when links are opened in a new tab (`target="_blank"`).

= 1.0.1 =
* Added: Inline script on the frontend to automatically rewrite relative `/?tag=XXX&to=` hrefs to absolute URLs based on the site's home URL.
* Fixed: `steclick_enqueue_url_fixer()` now returns early on admin pages.

= 1.0.0 =
* Initial release.