Get started

What is a view/hit

Counting a page view/visit is a surprisingly messy business. On one side of the spectrum, you can count every time a user visits a page. This way even a page refresh counts as unique visit. On the other hand, you can use fingerprinting, cookies and other techniques to track all users' actions on the web-site and determine if user’s return to the page qualifies as a new view.

To abide with our principles we chose the first approach and do not track users at all and stay at the privacy-oriented side of the spectrum. We plan to add privacy-conscious cookies to allow for a richer logic in the near future.

Installation

You can start counting visits in three simple steps:

  1. Register [↪]. Here you will need to provide only your email and you will get an access code there. No need for passwords.

  2. Create a counter using its domain name. All data gathered will be related to a counter. You may have any number of counters.

  1. Add the counter to you site. There are two ways to do it: using REST API or image counters.

API

To record a visit you need to send a post request to the following endpoint: https://app.countina.io/api/v1/count/?counter=[COUNTER_KEY]&url= + url or string you want to attribute the visit to. You can copy ready to use url in the counter view after you log in:

The key is not secret and is used only to identify the counter. It cannot be used to access your account.

The body of the request should be empty. In return you get a raw int with current number of visits to the provided url in this counter, including the visit in question.

For instance this code is used on this page to record visits in this web-site:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<script>
    const fetchAndUpdateCounter = async () => {
        const pageUrl = "{{ .Permalink }}"; // Hugo replaces it with a link to the page
        const apiUrl = "https://app.countina.io/api/v1/count/?counter=[COUNTER_KEY]&url=" 
                        + encodeURIComponent(pageUrl);
        try {
            const response = await fetch(apiUrl, {
                method: "POST",
            });
            // Optional: display number of visits in the element with id="countina-visits"
            if (response.ok) {
                const text = await response.text();
                const el = document.getElementById("countina-visits");
                if (el !== null) {
                    el.innerHTML = text;
                }
            } else {
                console.error("Fetching data was unsuccessfull");
            }
        } catch(error) {
            console.log(error);
        }
    }
    fetchAndUpdateCounter();
</script>

Images

Coming soon.

Retrieving number of visits

Sometimes you need to get number of visits without changing it. You can do it by accessing the following url with a GET request: https://app.countina.io/api/v1/visits/?counter=[COUNTER_KEY]&url= + url in question. In return you will get number of visits to this url for this counter.

This endpoint is open and accessible to anyone, so the information about number of visits is not restricted by default.

Counter settings

By default the counter will accept as url any arbitrary string, regardless if it is a valid url or not. This includes url to a different site (other than the domain of the counter). You can restrict recording visits only to urls which belong to the same domain as the counter.

This way all other urls will be ignored.

countina.io © 2021
 info@countina.io