=== useClick ===
Contributors: useclick
Tags: link shortener, url shortener, short links, click tracking, website analytics
Requires at least: 6.5
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.5.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Link shortener for WordPress: short links for posts and any URL, click tracking in wp-admin and cookie-free website analytics.

== Description ==

UseClick.io (https://useclick.io) is a URL shortener with click tracking and privacy-first website analytics. This plugin connects your WordPress site to your UseClick.io account, so you can create short links, see their clicks and read your visitor reports without leaving wp-admin.

= Short links =

* Create a short link for any URL on the built-in short domain or on your own branded domain.
* Pick a custom slug or let UseClick.io generate one.
* A Short link box in the post editor and a Short link column in the post and page lists, with click counts.
* A Short links screen with search, campaign filter, click counts, copy, edit and delete.
* Campaigns, UTM parameters and geo-targeting (send visitors from chosen countries to a different URL) on the Starter plan and above.
* Detailed click analytics (countries, devices, browsers, referrers) open in your UseClick.io dashboard.

= Website analytics =

* Pick one of your UseClick.io websites and switch tracking on. The plugin adds the UseClick.io tracker to the head of every public page.
* No cookies. IP addresses are not stored. Browsers with Do Not Track turned on are skipped.
* Administrators are not counted by default; you can also skip all logged-in users.
* Free plan: one website as a 14-day trial. Starter and above: 5 to 100 websites.
* Optional, off by default: report visits by AI assistants and search bots (ChatGPT, Claude, Perplexity, Google) that never run JavaScript.

= Plan-aware =

The plugin reads your plan from the API and marks features your plan does not include, so you do not fill in fields that the API would reject. When a request needs a higher plan, the error names the plan and links to the pricing page.

= Account required =

This plugin is a client for the UseClick.io service and needs a UseClick.io account. A free plan is available (10 links, 1,000 tracked clicks per month).

== External services ==

This plugin connects to UseClick.io, a link shortening and analytics service run by UseClick.io. Nothing is sent to UseClick.io until you click Connect with useClick.io or save an API key on the Settings screen.

**Connect with useClick.io (https://useclick.io/dashboard/connect/wordpress and https://useclick.io/api/integrations/wordpress/exchange)**

Only when you click Connect with useClick.io. Your browser is sent to useclick.io with this site's address, the address of its wp-admin and a random one-time value; after you sign in and confirm, it returns to wp-admin with a one-time code. WordPress then sends that code and this site's address to UseClick.io and receives an API key for this site. Nothing else about your site or its users is sent.

**UseClick.io API (https://useclick.io/api/v1)**

Used to check your API key and read your plan, list your branded domains and Website Analytics websites, add this site to Website Analytics, and create, list, update and delete short links. Requests are sent when you save or test a key, open the plugin's screens, create or edit a link, open the post editor or a post list (to show click counts, cached for five minutes), or click Create short link for a post. Each request carries your API key. When you create or edit a link it also carries the link details you entered: destination URL, slug, domain, campaign, UTM parameters, country targets and, for posts, the post title.

**Reports on the Website analytics screen (https://useclick.io/api/v1/websites/{id}/stats)**

When this site is tracked and an administrator opens the Website analytics screen, WordPress asks the UseClick.io API (with your API key) for this website's numbers: visitors, page views, top pages, sources, countries, devices, browsers and bots for the chosen date range. The answer is cached for five minutes and drawn on that screen by the plugin; nothing is loaded from useclick.io in the browser.

**UseClick.io tracker (https://useclick.io/analytics.js)**

Only if you turn on Website analytics. The script is loaded by your visitors' browsers on public pages and sends the page path, referrer, screen width and the website ID to UseClick.io. UseClick.io reads browser, device type, operating system and approximate location (country, region, city) from the request and counts unique visitors with a hash that changes every day. No cookies are set and IP addresses are not stored.

**Bot visit reporting (https://useclick.io/api/analytics/server-hit)**

Only if you turn on Website analytics and also tick "Report visits by ChatGPT, Claude, Perplexity, Google and other bots" (off by default). When a request to your site comes from a known bot user agent, WordPress records the page address, the bot's user agent, the referrer, the visitor country header set by Cloudflare (if present) and your website ID, and sends these records to UseClick.io in batches every few minutes, authenticated with your API key. Requests from people are never sent this way and no IP addresses are sent.

**Bot list (https://useclick.io/api/analytics/bot-signatures)**

Only while bot visit reporting is on. Once a day WordPress downloads the current list of bot user-agent names from UseClick.io. No data about your site or visitors is sent with this request.

* Terms of service: https://useclick.io/terms
* Privacy policy: https://useclick.io/privacy

== Installation ==

1. Install and activate the plugin.
2. Click "Connect with useClick.io" (in the notice on the Dashboard or under UseClick.io > Settings).
3. Sign in on useclick.io, or create a free account (only an email address is needed), and click Connect. You come straight back to WordPress, connected. No key to copy: the plugin receives its own API key, named after your site, directly from UseClick.io.
4. Create links under UseClick.io > Create link, or from the Short link panel when you edit a post.
5. Website analytics starts by itself when you connect: the plugin adds this site's domain to your UseClick.io account (or uses the website you already have for it), adds the cookie-free tracker, and shows the reports under UseClick.io > Website analytics.

Prefer to paste a key? In your UseClick.io dashboard open Account > API keys (https://useclick.io/dashboard/account/api-keys), click "+ Create API key", name it after your site and click "Create key". Then open UseClick.io > Settings > "Or paste an API key".

Step-by-step guide: https://useclick.io/docs/wordpress-plugin

== Frequently Asked Questions ==

= Do I need a UseClick.io account? =

Yes. The plugin connects to your UseClick.io account with an API key. The free plan includes 10 links and 1,000 tracked clicks per month.

= Do I need an API key? =

No. Click "Connect with useClick.io", sign in or sign up, and confirm: the plugin gets its own key automatically. If you prefer, create a key under Account > API keys in your UseClick.io dashboard and paste it under UseClick.io > Settings > "Or paste an API key". The full guide is at https://useclick.io/docs/wordpress-plugin.

= Which features need a paid plan? =

Campaigns, UTM parameters, geo-targeting and changing a link's destination after it is created need the Starter plan or above. Website analytics is included on Free as a 14-day trial for one website (visits are recorded for 7 more days after the trial), and on Starter and above. The plugin marks these features when your plan does not include them.

= Who can create short links? =

The UseClick.io screens need the manage_options capability (administrators). The Short link box and column are available to users who can edit other people's posts (editors and administrators), for posts they can edit. Developers can change both with the `useclick_capability` and `useclick_post_link_capability` filters.

= Does the tracker set cookies? =

No. Unique visitors are counted with a hash that changes every day, and IP addresses are not stored. Whether your site needs a consent banner depends on everything else it loads, so check with your own legal advice.

= Does the tracker count me while I test? =

Not while you are logged in as an administrator, unless you untick "Administrators" under Do not count.

= Can I use my own domain for short links? =

Yes. Add a branded domain in your UseClick.io dashboard. It then appears in the domain list when you create a link.

= What happens to my links if I remove the plugin? =

Your links keep working; they live in your UseClick.io account. Deleting the plugin removes its settings and the short links saved on your posts from the WordPress database.

= Can I point the plugin at a different server? =

For testing, define `USECLICK_API_BASE_URL` in wp-config.php or use the `useclick_api_base_url` filter. The tracker URL can be changed with `USECLICK_TRACKER_URL` or the `useclick_tracker_url` filter.

== Screenshots ==

1. Create link screen: domain, custom slug, campaign, UTM parameters and geo-targeting, with your plan's usage.
2. Short links list with click counts, campaigns, copy, edit and delete.
3. Settings: connection status, plan and limits.
4. Website analytics settings: who is not counted, optional AI bot reporting and what is collected.
5. Short link column in the posts list, with click counts.
6. Short link panel in the block editor sidebar.

== Credits ==

The admin screens use Plus Jakarta Sans (SIL Open Font License 1.1, assets/fonts/OFL.txt), bundled with the plugin; no fonts are loaded from other servers.

== Changelog ==

= 1.5.0 =
* New: Short link panel in the block editor sidebar (the classic Short link box stays for the Classic Editor).
* New: redesigned screens in the useClick.io look, while buttons and links follow your admin colour scheme.
* New: Free plan users can use the 14-day website analytics trial; the screen shows trial days left, the grace week and when tracking stops.
* Changed: the plugin's folder and text domain are now "useclick". If you installed an earlier version from a zip file, deactivate and delete the old copy after installing this one; your settings are kept.
* New: Connect with useClick.io: sign in or create a free account on useclick.io, confirm, and come back connected. No API key to copy. A setup notice on the Dashboard and Plugins screens points new installs to it until the site is connected (dismissible).
* New: the plugin screens use the useClick.io dashboard look (fields, buttons, type). A Your plan card shows what your plan includes, the 14-day website analytics trial on Free and what Starter adds, with an upgrade button. A What you can do card lists the features.
* Fix: the plan badges next to Campaign, UTM parameters and Geo-targeting were empty; they now read Starter+.
* New: website analytics starts automatically when you connect, and the reports (visitors, pages, sources, countries, devices, AI bots) are shown right in wp-admin under UseClick.io > Website analytics.
* New: website analytics in one click: Start tracking adds this site's domain to your UseClick.io account (or finds the existing website for it) and switches the tracker on. No need to add the site in the dashboard first.
* Fix: unticking "Administrators" under Do not count did not save on a fresh install.
* New: step-by-step help for getting an API key on the Settings screen, a Help tab on every UseClick.io screen, and links to the setup guide at useclick.io/docs/wordpress-plugin.
* New: Site Health check for the connection, a UseClick.io section in Site Health > Info, and suggested text for your privacy policy.
* New: set the API key in wp-config.php with define( 'USECLICK_API_KEY', '...' ) to keep it out of the database.
* Changed: reporting bot visits is now opt-in and off by default. If it was on in 1.4.0, it is switched off by this update until you turn it on again.
* Changed: bot visits are recorded only for bot user agents and sent in batches every few minutes by WP-Cron, instead of one request per visit; the bot list is refreshed daily in the background, never during a visitor's request.
* Changed: the tracker is loaded with the WordPress defer strategy (requires WordPress 6.5 or newer).
* Fix: click counts in the post lists for posts whose short link is older than the 100 newest links.
* Fix: admin screens no longer wait for a slow connection: failures are remembered for a minute and reads time out sooner.
* Accessibility: the edit dialog keeps focus inside, copy actions are announced to screen readers, and links that open a new tab say so.

= 1.4.0 =
* New: see which AI assistants and bots read your site. WordPress reports visits by ChatGPT, Claude, Perplexity, Google and other bots to UseClick.io (most of them never run the JavaScript tracker). One background request per bot visit, never for people, no IP addresses. On by default; switch it off under Website analytics.

= 1.3.0 =
* New: Short link box in the post editor and Short link column (with click counts) in post and page lists.
* New: settings show the connected plan, limits and rate limit; the key is checked before it is saved and can be disconnected.
* New: errors from the API name the plan a feature needs and link to pricing; rate limit errors say how long to wait.
* Fix: geo-targeting rules were lost when a link was created from WordPress.
* Fix: quotes and apostrophes in campaigns and UTM values were saved with backslashes.
* Fix: editing a link sends only the fields you changed, so unchanged values never trigger a plan check.
* Fix: Free plan users see that the destination cannot be changed instead of an error.
* The tracker is now added with wp_enqueue_script, and skipped in previews and the Customizer.
* The API key is no longer printed into admin pages or passed to JavaScript.
* Security: all output escaped, all input unslashed and sanitized, nonces and capability checks on every action.
* Text domain changed to useclick-link-shortener to match the plugin slug.

= 1.2.0 =
* UTM parameters can be edited after a link is created.
* Short links display and copy with the correct domain (branded or built-in).
* Plan-aware interface and account summary.
* Uninstall cleanup.

= 1.1.0 =
* Website analytics module.

= 1.0.0 =
* Initial release.

== Upgrade Notice ==

= 1.5.0 =
Connect with one click, no API key to copy. Installed an earlier version from a zip? Delete the old copy after updating; settings are kept. Bot visit reporting is now opt-in and off after this update. Requires WordPress 6.5 or newer.

= 1.3.0 =
Fixes lost geo-targeting rules and backslashes in campaign names, adds short links for posts, and hardens security. Recommended for all users.
