simple self-hosting visitor tracking library in javascript
- Upload files to your server
- Edit them and adjust relative paths
- Import DB Structure
- Include script to your project
- You are done
Embed the following code into your footer
Compressed:
<!-- Begin Visitor Count -->
<script id="vc-src" src="PATH_TO_YOUR_CWD/visitorjs/ajax.js"></script>
<script id="ajax-src" src="PATH_TO_YOUR_CWD/visitorjs/visitor.js"></script>
<script type="text/javascript">let counter=new VisitorCounter("exact_loc",function(e){console.log(e)});counter.make();</script>
<!-- End Visitor Count -->
Fullscale:
<!-- Begin Visitor Count -->
<script id="vc-src" src="PATH_TO_YOUR_CWD/visitorjs/ajax.js"></script>
<script id="ajax-src" src="PATH_TO_YOUR_CWD/visitorjs/visitor.js"></script>
<script type="text/javascript">
// initialize counter
let counter = new VisitorCounter('exact_loc', function(data) { console.log(data); });
// start counting
counter.make();
</script>
<!-- End Visitor Count -->
In Case you want to display the current visitor count, use .useContainer()
before you call .make()
. Read more about that below.
new VisitorCounter(LOCATION, CALLBACK, TEST);
@param {string} LOCATION
: exact_loc | host_only
Track the exact location or the hostname
(e.g track https://www.google.com instead of https://www.google.com/search?q=a)
@param {callback} CALLBACK
: any function, receives server reply as data
Callback Function for Ajax Call to backend API which receives an argument called 'data' containing the server's answer
@param {boolean} TEST
: true | false
Enable this to prevent database spam when working on the tracked site. This option will disable actual tracking
myCounter.useContainer(ELEMENT);
@param {external:Node} ELEMENT
: null | any node
Pass this in case you want to use an own container element. If you leave it empty, it will fallback to standard element with id 'visitor-count'.