JD Visitor Counter - API

How to add a counter to your HTML page

Insert this sample code on your website:

<div>Host All: <span class="host-all">-</span></div>
<div>Host Online: <span class="host-online">-</span></div>
<div>URL All: <span class="url-all">-</span></div>
<div>URL Online: <span class="url-online">-</span></div>

<script src="https://jd-visitor-counter.adaptable.app/script.min.js" async></script>
<script>
  window.addEventListener('load', () => {
    if ('VisitorCounter' in window) VisitorCounter({
      elements: {
        hostAll: '.host-all',
        hostOnline: '.host-online',
        urlAll: '.url-all',
        urlOnline: '.url-online'
      }
    })
  })
</script>

Note: If the user's browser has "Do Not Track" enabled, it will not be counted

Types of counters

VisitorCounter

VisitorCounter(options)

options

Full example

VisitorCounter({
  elements: {
    hostAll: '.host-all',
    hostOnline: '#host-online, .online',
    urlAll: '.url-all .users',
    urlOnline: 'span.url-online'
  },

  onUpdate: {
    hostAll: (n) => console.log(n),
    hostOnline: updateOnlineUsersCounter,
    urlAll: function (numberOfUsers) {
      document.querySelector('.url-all').innerText = numberOfUsers
    },
    urlOnline: console.log
  },

  onLoad: function () {
    alert('Counter loaded!')
  },

  doNotUseWebSocket: true
})

Custom counter

This returns an animated SVG image with the amount of visitors

Useful for putting on GitHub or pages that don't allow scripting

GET https://jd-visitor-counter.adaptable.app/custom/<id>/count.svg

<id> Any string

Visitor counter

Example for GitHub:

![Visitor counter](https://jd-visitor-counter.adaptable.app/custom/github:YOURUSERNAME/count.svg)

Customizations

Customize the counter through query parameters

Examples:

Visitors

Host All: -
Host Online: -
URL All: -
URL Online: -

Developed by Jefferson Dantas