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.onrender.com/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
hostAll: Counts people who have visited any page on the domainhostOnline: Only counts people who are online on any page of the domainurlAll: Counts people who have only visited this site pageurlOnline: Count people who are online on this page of the siteVisitorCounterVisitorCounter(options)optionselements: object
Selectors where the counter numbers will appear
hostAll: string (CSS selectors)hostOnline: string (CSS selectors)urlAll: string (CSS selectors)urlOnline: string (CSS selectors)Example:
{
elements: {
hostAll: '.host-all',
hostOnline: '#host-online, .online',
urlAll: '.url-all .users',
urlOnline: 'span.url-online'
}
}onUpdate: object
Run a function when updating the data
hostAll: functionhostOnline: functionurlAll: functionurlOnline: functionExample:
{
onUpdate: {
hostAll: (n) => console.log(n),
hostOnline: updateOnlineUsersCounter,
urlAll: function (numberOfUsers) {
document.querySelector('.url-all').innerText = numberOfUsers
},
urlOnline: console.log
}
}onLoad: function
Execute a function when loading the counter
Example:
{
onLoad: function () {
alert('Counter loaded!')
}
}doNotUseWebSocket: boolean
Does not use WebSocket to update data in real time Default: false
Example:
{
doNotUseWebSocket: true
}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
})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.onrender.com/custom/<id>/count.svg
<id> Any string
Example for GitHub:
Customize the counter through query parameters
primaryColor: string (CSS color)
Change the background color of the primary boxes
secondaryColor: string (CSS color)
Change the background color of the secondary boxes
textColor: string (CSS color)
Change text color
minDigits: number
Minimum number of digits to be displayed (min. 1 / max. 20)
Examples:
https://jd-visitor-counter.onrender.com/custom/foo/count.svg?primaryColor=redhttps://jd-visitor-counter.onrender.com/custom/foo/count.svg?primaryColor=red&secondaryColor=green&textColor=yellow&minDigits=10https://jd-visitor-counter.onrender.com/custom/foo/count.svg?primaryColor=%23ff0000Note: To use hash character (
#) use%23instead
Developed by Jefferson Dantas