Skip to content

Navigation Menu

Sign up
risingisland edited this page Dec 3, 2026 · 1 revision

Click Counter

A lightweight, standalone GetSimpleCMS-CE plugin for tracking clicks on any link or button - no login required.

Installation

  1. Copy both gs_Clicks.php and the gs_Clicks/ folder into your GetSimpleCMS plugins/ directory, as siblings:
    plugins/
    ├── gs_Clicks.php
    └── gs_Clicks/
    
  2. Open Settings → Plugins in the admin panel and activate GS Click Counter.
  3. Set a real random value for GSCC_SALT in gs_Clicks.php before going live (it's used to anonymize IP addresses in the database - don't leave the default).
  4. That's it - the SQLite database is created automatically at data/other/gs_Clicks.db on first use.

Usage

Shortcode (in page/post content)

{gs-click id="ebook-pdf" url="/files/ebook.pdf" label="Download PDF"}

Add show_count="1" to display the current total next to the link:

{gs-click id="ebook-pdf" url="/files/ebook.pdf" label="Download PDF" show_count="1"}

Customize the count text with count_format (%d is replaced with the number):

{gs-click id="ebook-pdf" url="/files/ebook.pdf" label="Download PDF" show_count="1" count_format="Downloads: %d"}

Template tag (in theme files)

<?php gs_click_link('ebook-pdf', '/files/ebook.pdf', 'Download PDF'); ?>
<?php gs_click_link('ebook-pdf', '/files/ebook.pdf', 'Download PDF', ['show_count' => true, 'count_format' => 'Downloads: %d']); ?>

Tracking an existing link or button directly

You don't need the shortcode or template tag at all - add data-gsc-id to any existing <a> or <button> already in your theme or page HTML, and it's tracked automatically:

<a href="/files/ebook.pdf" data-gsc-id="ebook-pdf">Download PDF</a>

This is how you track links you already have full control over the markup for - buttons with custom classes, existing download links, anything.

Popular downloads list

Shows a ranked list of the most-clicked links, with working hyperlinks - as long as each one was rendered at least once through the shortcode or template tag (that's what lets the plugin remember its URL and label). IDs tracked only via a bare data-gsc-id attribute show up by ID only, since the plugin never saw their URL.

{gs-click-top limit="5"}
<?php gs_click_top_list(5); ?>

Dynamic / JS-rendered content

Same data-gsc-id attribute, just added inside JS-built markup. After inserting new elements into the page, call GSClicks.init() to wire up anything not already bound:

const cardHTML = `<a href="${url}" class="btn btn-primary" data-gsc-id="${id.toLowerCase()}">Download</a>`;
// ...insert cardHTML into the page...
GSClicks.init();

init() is safe to call repeatedly - already-bound elements are skipped. Use GSClicks.getCounts(ids) if you want to display live counts in your own custom markup instead of show_count:

GSClicks.getCounts(['ebook-pdf', 'other-file']).then(function (counts) {
 console.log(counts['ebook-pdf']); // e.g. 42
});

Or GSClicks.getTop(limit) for a ranked popular-downloads list instead of the {gs-click-top} shortcode:

GSClicks.getTop(5).then(function (top) {
 // top is [{ id, count, url, label }, ...] sorted by count descending
});

Per-item counts in a card layout

For a page of item cards (galleries, plugin listings, etc.) built in JS, add a placeholder next to each item's title or button, then fill in the real counts in one batch request once all cards exist:

const cardHTML = `
 <div class="card">
 <h5>${name}</h5>
 <a href="${url}" class="btn btn-primary" data-gsc-id="${id}">Download</a>
 <span class="download-count" data-gsc-count-for="${id}">Downloads: ...</span>
 </div>`;
// ...insert all cards into the page, then:
GSClicks.init();
GSClicks.getCounts(items.map(i => i.id)).then(function (counts) {
 document.querySelectorAll('[data-gsc-count-for]').forEach(function (el) {
 const id = el.dataset.gscCountFor;
 el.textContent = 'Downloads: ' + (counts[id] || 0);
 });
});

getCounts() takes any number of IDs in a single request, so this works the same whether the page has 5 cards or 500.

Available attributes

Attribute Values Default
id any unique string required
url any URL required
label any text same as id
show_count 0, 1 0
count_format text with %d, e.g. "Downloads: %d" (%d)
target e.g. _blank -

Anti-spam approach

No login is required to track a click, so anonymous dedup uses the same approach as GS Ratings: a salted hash of the visitor's IP address plus a random token stored client-side. Unlike a rating, there's no "value" to update - a click either counts or doesn't. The anti-spam window (Settings tab, in minutes) controls how long a repeat click from the same visitor on the same link is ignored before counting again. Set it to 0 to count every single click with no deduping at all.

Reference

AltStyle によって変換されたページ (->オリジナル) /