Google Tag Manager

Install HitCounters via Google Tag Manager

If your site is already running through GTM, this is the cleanest way to add HitCounters. About 3 minutes.

Get tracking code first

Step-by-step

  1. Get your tracking code from your HitCounters Sites page (16 characters, e.g. ABC123DEF456GHI7).
  2. In GTM, open your container and create a new Variable:
    • Type: Constant
    • Name: HitCounters Tracking Code
    • Value: paste your 16-character code
  3. Create a new Tag:
    • Type: Custom HTML
    • Name: HitCounters - Tracker
    • HTML:
      <!-- HitCounters.com -->
      <script async src="https://hitcounters.com/api/tracker.js?code={{HitCounters Tracking Code}}"></script>
      <noscript><img src="https://hitcounters.com/api/track.php?code={{HitCounters Tracking Code}}&noscript=1" alt="" style="display:none;"/></noscript>
    • Trigger: All Pages
  4. Save and Publish the GTM container.
  5. Verify on your HitCounters Sites page.

Track conversions via GTM (optional)

To fire HitCounters events from a GTM trigger (form submit, button click, custom event), add another Custom HTML tag with this body:

<script>
  if (typeof hcEvent === 'function') {
    hcEvent('signup');             // event name from your Goals page
    // hcEvent('purchase', 49.99);  // with optional value
  }
</script>

Then add a goal of type Event on your Goals page with the matching name. Conversions will appear in your dashboard within seconds.

Troubleshooting

  • Verification fails? Make sure you published the GTM container, not just saved a draft.
  • Tag not firing? Use GTM Preview mode and confirm the tag is listed under "Tags Fired" on a page load.
  • Cloudflare cache? Purge the page cache after publishing your GTM container.
  • CSP blocking? If you have a Content Security Policy, allow script-src https://hitcounters.com.

Don't have GTM?

No problem — the regular snippet works on any site, and we have one-click installs for WordPress.

WordPress instructions Sign up free