Click Counter Documentation

SSP — Click Counter (Docs)

SSP Documentation

Click Counter

Admin Screen

The plugin adds a single menu item in your WordPress admin sidebar called Click Counter (cursor icon). It opens one screen with a table for managing selectors and counts:

  • CSS Selector — the actual DOM selector to track (e.g. .buy-now, #signup-button).
  • Name — optional human-readable label for the selector.
  • Clicks — running total of tracked clicks.
  • Edit — unlocks fields for editing selector or name.
  • Reset — zeroes out the click count for that row.
  • Delete — removes the row entirely.
Tip: At least 10 rows are shown by default, so you can add selectors quickly without manual table expansion.

Bulk Actions

  • Add New Selector — appends a blank row to the table.
  • Save All Changes — commits edits and new rows to the database.
  • Reset All Counts — clears every count to zero across all selectors.

How It Works

The plugin registers a lightweight JavaScript listener on document.body that checks for clicks matching any saved selector. When a match is found:

  1. The script sends an AJAX POST to admin-ajax.php with the selector and a security nonce.
  2. The server verifies the nonce, confirms the selector is allowed, and increments its counter in wp_options.
  3. No page reload occurs; increments are seamless.

Reset actions are also AJAX-powered. Individual rows can be reset without a reload. “Reset All” clears all counts at once.

Privacy & Data

Click Counter is designed for minimal data use:

  • Storage: All selectors and click counts are stored in WordPress options (mcc_selectors, mcc_click_counts).
  • No personal data: The plugin never logs IP addresses, users, or sessions — only aggregate click totals per selector.
  • Security: All AJAX calls are protected with WordPress nonces to prevent unauthorized increments or resets.
  • Reset safety: Counts can be cleared, but selectors remain unless explicitly deleted.

Troubleshooting

Clicks aren’t being counted
  • Ensure your CSS selector is valid (try it in browser DevTools).
  • Confirm the element exists when the page loads (dynamic elements may need broader selectors).
  • Check that the plugin is enabled and selectors are saved (look for “Selectors saved.” notice in admin).
Counts don’t update immediately

Counts are updated in the database via AJAX but are only visible after refreshing the admin page. Clicks still register even if the number doesn’t change instantly.

Reset doesn’t work
  • Ensure you clicked the Reset button for a row with an existing selector (blank rows cannot be reset).
  • Verify nonces are valid — reloading the admin page generates fresh nonces.
  • For bulk resets, look for the “All counts reset.” notice after submission.
Deleted selector reappears

Deleting a row only removes it from the form. To confirm removal, click Save All Changes. Without saving, deletions are not permanent.

Test / Verification

  1. In admin, add a selector like #test-button with the name “Test.” Save changes.
  2. On the frontend, add a button with id="test-button".
  3. Click the button several times.
  4. Return to the Click Counter admin screen and confirm the count increases.
  5. Use the row’s Reset button and check the count resets to 0.
Tip: Use DevTools console (document.querySelectorAll()) to validate selectors before adding them.