Tracking
Goals
Count sign-ups, downloads, purchases or any click, and see which sources and pages lead to them.
What a goal is
Pageviews tell you how many people came. A goal tells you how many did the thing you built the page for: signed up, downloaded the file, clicked “Buy”.
A goal is a name and nothing else. You pick the name, your website reports it when the thing happens, and the dashboard counts how often it was reached and by what share of your visitors. There is nothing to set up in the dashboard first: a new name appears in the Goals list by itself the first time it is reached.
There are two ways to report a goal. Both need the script installed.
Count a click, without writing code
Add the attribute data-fivebar-goal to a link or a button, with the goal’s name as its value:
<a href="/signup" data-fivebar-goal="signup">Create an account</a>Every click on it counts once. Good to know:
- It works on any element, and a click on something inside it counts too, like the icon in this button:
<button data-fivebar-goal="download brochure">
<img src="/pdf.svg" alt=""> Download the brochure
</button>- It works on links that leave the page, including links to other websites and file downloads. The browser sends the report in the background while the next page loads.
- It counts clicks, not results. A click on “Submit” counts even if the form then shows an error. To count only what succeeded, report the goal from your code instead.
Count it from your own code
The script adds one function to your page. Call it with the goal’s name at the moment the thing has happened:
fivebar('signup')For example, after a newsletter form was accepted by your server:
const form = document.querySelector('#newsletter');
form.addEventListener('submit', async (event) => {
event.preventDefault();
const response = await fetch('/subscribe', { method: 'POST', body: new FormData(form) });
if (response.ok) fivebar('newsletter'); // count it only when it really worked
});Calling it while the page is still loading
The script loads after the page has been drawn, so fivebar does not exist yet while the page is
still loading. Code that runs on a click or after a form was sent is fine: by then the script is there. Code
that runs straight away is not, for example a “thank you” page that reports a purchase as soon as it opens.
For that case, put this one extra line before the Fivebar line. It collects early calls, and the script counts them as soon as it has loaded:
<script>
window.fivebar = window.fivebar || function () { (fivebar.q = fivebar.q || []).push(arguments) }
</script>
<script defer src="https://script.fivebar.eu/latest.js" data-site="your-site-id"></script><!-- on the "thank you" page, anywhere after the two lines above -->
<script>fivebar('purchase')</script>Rules for names
| Allowed characters | Letters a to z, digits, spaces, _ and - |
|---|---|
| Length | 1 to 40 characters |
| Capital letters | Turned into small letters. Sign Up and sign up are the same goal. |
| Anything else | The goal is not counted, and nothing tells you. That includes dots, slashes, @, accented letters and emoji. |
| Works | Does not work | Why |
|---|---|---|
signup | sign-up! | “!” is not allowed |
download brochure | download/brochure.pdf | “/” and “.” are not allowed |
plan-pro | purchase 49.90 | “.” is not allowed, and an amount is a detail, not a name |
kontakt | anmeldung-für-newsletter | “ü” is not allowed; write fuer |
Pick a handful of names and keep them stable. signup today and sign-up next month
are two different goals with two separate counts.
Goals in the dashboard
The Goals list sits next to Pages and Sources. For each goal it shows:
- Times reached in the period you are looking at.
- A percentage: the share of all visitors in that period who reached it at least once. This is your conversion rate for that goal.
Click a goal to filter the whole dashboard by it. Every number and list then describes only the visitors who reached that goal: which sources they came from, which pages they read, which countries they are in. Add a second filter, for example a source, to ask “how many newsletter readers signed up?”. More about filters.
What goals cannot do
- No values. A goal has no amount, no product and no other detail attached. To tell two plans
apart, use two names:
plan-basicandplan-pro. - No memory beyond a day. Fivebar cannot recognise a visitor the next day, on purpose. Someone who reads your site on Monday and signs up on Tuesday is counted as Tuesday’s visitor, with Tuesday’s source.
- No protection against double counting. Two clicks are two reports. If a goal should count once per person, report it from the page or the moment that only happens once.
A goal that does not show up? See Troubleshooting.