• Stars
    star
    4,235
  • Rank 10,098 (Top 0.3 %)
  • Language
    Go
  • License
    Other
  • Created over 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Easy web analytics. No tracking of personal data.

GoatCounter is an open source web analytics platform available as a (free) hosted service or self-hosted app. It aims to offer easy to use and meaningful privacy-friendly web analytics as an alternative to Google Analytics or Matomo.

There are two ways to run this: as hosted service on goatcounter.com, or run it on your own server. The source code is completely Open Source/Free Software, and it can be self-hosted without restrictions.

See docs/rationale.markdown for some more details on the "why?" of this project.

There's a live demo at https://stats.arp242.net.

Please consider contributing financially if you're using goatcounter.com to pay for the server costs.

Features

  • Privacy-aware; doesn’t track users with unique identifiers and doesn't need a GDPR notice. Fine-grained control over which data is collected. Also see the privacy policy and GDPR consent notices.

  • Lightweight and fast; adds just ~3.5K of extra data to your site. Also has JavaScript-free "tracking pixel" option, or you can use it from your application's middleware or import from logfiles.

  • Identify unique visits without cookies using a non-identifiable hash (technical details).

  • Keeps useful statistics such as browser information, location, and screen size. Keep track of referring sites and campaigns.

  • Easy; if you've been confused by the myriad of options and flexibility of Google Analytics and Matomo that you don't need then GoatCounter will be a breath of fresh air.

  • Accessibility is a high-priority feature, and the interface works well with assistive technology such as screen readers.

  • 100% committed to open source; you can see exactly what the code does and make improvements, or self-host it for any purpose.

  • Own your data; you can always export all data and cancel at any time.

  • Integrate on your site with just a single script tag:

    <script data-goatcounter="https://yoursite.goatcounter.com/count"
            async src="//gc.zgo.at/count.js"></script>
    
  • The JavaScript integration is a good option for most, but you can also use a no-JavaScript image-based tracker, integrate it in your backend middleware, or parse log files.

Getting data in to GoatCounter

There are three ways:

  1. Add the JavaScript code on your site; this is the easiest and most common method. Detailed documentation for this is available at https://www.goatcounter.com/code

  2. Integrate in your middleware; send data to GoatCounter by calling the API from your backend server middleware. Detailed documentation for this is available at https://www.goatcounter.com/api#backend-integration

  3. Parse logfiles. GoatCounter can parse logfiles from nginx, Apache, CloudFront, or any other HTTP middleware or proxy. See goatcounter help import for detailed documentation on this.

Running your own

Note this README is for the latest master and may be inaccurate for the latest released version; use the release-2.4 branch for the 2.4 README.

The release page has binaries for Linux amd64, arm, and arm64. These are statically compiled, contain everything you need, and should work in pretty much any Linux environment. The only other thing you need is somewhere to store a SQLite database file or a PostgreSQL connection.

GoatCounter should run on any platform supported by Go, but there are no binaries for them (yet) as cross-compiling SQLite is somewhat complex. You'll have to build from source if you want to run it on e.g. FreeBSD or macOS.

Generally speaking only the latest release is supported, although critical fixes (security, data loss, etc.) may get backported to previous releases.

Deploy scripts and such

Building from source

You need Go 1.19 or newer and a C compiler (for SQLite). If you compile it with CGO_ENABLED=0 you don't need a C compiler but can only use PostgreSQL.

You can install from source to $GOBIN (go env GOBIN) with:

% git clone --branch=release-2.4 https://github.com/arp242/goatcounter.git
% cd goatcounter
% go build -ldflags="-X zgo.at/goatcounter/v2.Version=$(git log -n1 --format='%h_%cI')" ./cmd/goatcounter

Which will produce a goatcounter binary in the current directory.

The -ldflags=[..] sets the version; this isn't strictly required as such, but it's recommended as it's used to "bust" the cache for static files and may also be useful later when reporting bugs. This can be any string and doesn't follow any particular format, you can also set this to the current date or banana or anything you want really.

To use the latest development version switch to the master branch.

To build a fully statically linked binary:

% go build -tags osusergo,netgo,sqlite_omit_load_extension \
    -ldflags="-X zgo.at/goatcounter/v2.Version=$(git log -n1 --format='%h_%cI') -extldflags=-static" \
    ./cmd/goatcounter

It's recommended to use the latest release as in the above command. The master branch should be reasonably stable but no guarantees, and sometimes I don't write detailed release/upgrade notes until the actual release so you may run in to surprises.

You can compile goatcounter without cgo if you're planning to use PostgreSQL and don't use SQLite:

% CGO_ENABLED=0 go build \
    -ldflags="-X zgo.at/goatcounter.Version=$(git log -n1 --format='%h_%cI')" \
    ./cmd/goatcounter

Functionally it doesn't matter too much, but builds will be a bit easier and faster as it won't require a C compiler.

Running

You can start a server with:

% goatcounter serve

The default is to use an SQLite database at ./db/goatcounter.sqlite3, which will be created if it doesn't exist yet. See the -db flag and goatcounter help db to customize this.

Both SQLite and PostgreSQL are supported. SQLite should work well for most smaller sites, but PostgreSQL gives better performance. There are some benchmarks over here to give some indication of what performance to expect from SQLite and PostgreSQL.

GoatCounter will listen on port *:80 and *:443 by default. You don't need to run it as root and can grant the appropriate permissions on Linux with:

% setcap 'cap_net_bind_service=+ep' goatcounter

Listening on a different port can be a bit tricky due to the ACME/Let's Encrypt certificate generation; goatcounter help listen documents this in depth.

You can create new sites with the db create site command:

% goatcounter db create site -vhost stats.example.com -user.email [email protected]

This will ask for a password for your new account; you can also add a password on the commandline with -password. You must also pass the -db flag here if you use something other than the default.

Updating

You may need to run the database migrations when updating. Use goatcounter serve -automigrate to always run all pending migrations on startup. This is the easiest way, although arguably not the "best" way.

Use goatcounter migrate <file> or goatcounter migrate all to manually run migrations; generally you want to upload the new version, run migrations while the old one is still running, and then restart so the new version takes effect.

Use goatcounter migrate pending to get a list of pending migrations, or goatcounter migrate list to show all migrations.

PostgreSQL

To use PostgreSQL run GoatCounter with a custom -db flag; for example:

% goatcounter serve -db 'postgresql+dbname=goatcounter'
% goatcounter serve -db 'postgresql+host=/run/postgresql dbname=goatcounter sslmode=disable'

This follows the format in the psql CLI; you can also use the PG* environment variables:

% PGDATABASE=goatcounter PGHOST=/run/postgresql goatcounter serve -db 'postgresql'

The database will be created automatically if possible; if you want to create it for a specific user you can use:

% createuser --interactive --pwprompt goatcounter
% createdb --owner goatcounter goatcounter

You can manually import the schema with:

% goatcounter db schema-pgsql | psql --user=goatcounter --dbname=goatcounter

See goatcounter help db and the pq docs for more details.

Development/testing

You can start a test/development server with:

% goatcounter serve -dev

The -dev flag makes some small things a bit more convenient for development; TLS is disabled by default, it will listen on localhost:8081, the application will automatically restart on recompiles, templates and static files will be read directly from the filesystem, and a few other minor changes.

See .github/CONTRIBUTING.markdown for more details on how to run a development server, write patches, etc.

More Repositories

1

uni

Query the Unicode database from the commandline, with good support for emojis
Go
776
star
2

hello-css

A CSS template focused on readability
CSS
178
star
3

find-cursor

Highlight the cursor position in X11
C
167
star
4

gopher.vim

Plugin for the Go programming language
Vim Script
116
star
5

zcache

In-memory key:value store/cache (similar to Memcached) library for Go, suitable for single-machine applications
Go
61
star
6

dotfiles

My configuration files
Shell
60
star
7

zli

Go library for writing CLI programs. Includes flag parsing, colours, testing, and various helpful utility functions
Go
39
star
8

jumpy.vim

Filetype-specific mappings for [[, ]], g[, and g]
Vim Script
38
star
9

arp242.net

This is my site. There are many like it, but this one is mine.
HTML
34
star
10

gogo-release

Build cross-platform binaries for Go
Shell
32
star
11

singlepage

Bundle external assets in a HTML file to distribute a stand-alone HTML document.
Go
26
star
12

toml-c

TOML C library
C
26
star
13

info

A simple GNU info replacement which isn't terrible
Go
24
star
14

bestasciitable

The best™ ASCII table
HTML
20
star
15

isbot

Go library to detect HTTP bots.
Go
19
star
16

follow

Go library to follow a file for changes; e.g. "tail -F".
Go
19
star
17

download-npo

Download episodes from the Dutch npostart.nl − Download afleveringen van npostart.nl
Python
18
star
18

undofile_warn.vim

Warn when using the undofile
Vim Script
18
star
19

sconfig

Simple and functional configuration file parser for Go.
Go
17
star
20

vimlog

A ChangeLog for Vim
HTML
16
star
21

packman.vim

Simple Vim plugin/package manager
Shell
14
star
22

runbuf.vim

Run the contents of a buffer in psql, python, bash, etc.
Vim Script
13
star
23

startscreen.vim

Customize Vim's start screen.
Vim Script
12
star
24

testing.vim

Comprehensive testing tool for Vim
Shell
12
star
25

ttftrim

Remove glyps from TTF fonts
Python
11
star
26

zdb

Interact with SQL databases in Go
Go
11
star
27

readon.js

Continue reading a web page from where you left last time
JavaScript
11
star
28

xdg_open.vim

Run xdg-open from Vim; re-implements netrw's gx.
Vim Script
11
star
29

auto_mkdir2.vim

Automatically create directories
Vim Script
10
star
30

zhttp

Martin's HTTP package
Go
10
star
31

MartinFox

Really simple userChrome.css for Firefox 89 to make the active tab stand out more
CSS
10
star
32

switchy.vim

Switch to related files
Vim Script
9
star
33

gadget

Go library to get the browser and OS from the User-Agent header.
Go
9
star
34

zprof

Display runtime profiling data for Go programs over HTTP
Go
9
star
35

my-first-vimrc

A vimrc generator that doesn't add a world of complexity
HTML
9
star
36

ff-hist

Search Firefox history from commandline
Shell
9
star
37

zsrv

Static file server which packs all data in the binary
Go
9
star
38

pkg_clearleaves

Easily remove packages on which no other packages depend
Python
8
star
39

blackmail

Go package to send emails with a friendly API
Go
8
star
40

lpeg.vim

LPeg-based syntax highlighting in Vim
Lua
8
star
41

colorcount

Display the colours used in a PNG image
Go
7
star
42

goatcounter-wordpress

WordPress plugin for GoatCounter
PHP
7
star
43

transip-dynamic

Dynamic DNS for TransIP
Go
6
star
44

imgzoom.js

JavaScript image zoomer
HTML
6
star
45

goimport

Add, remove, or replace imports in Go files
Go
6
star
46

sanitize_files

Basic cleanup of your code
Python
6
star
47

battray

Display tray icon with battery status; can also run scripts when the status changes
Python
5
star
48

helplink.vim

Link to Vim help pages with ease.
Vim Script
5
star
49

zev.vim

Easily apply predefined substitute patterns
Vim Script
5
star
50

zstd

Extensions to Go's stdlib
Go
5
star
51

gomodgraph

'go mod graph' as a nicely indented graph
Go
5
star
52

trackwall

DNS proxy and filter − /etc/hosts on steroids.
Go
4
star
53

rogue-clone

The "rogue" game from 4.3BSD-Tahoe, for modern systems.
C
4
star
54

goon

Run Go on another machine such as a QEMU VM or cloud instance
Shell
4
star
55

lazy.vim

The really simple snippet manager
Vim Script
4
star
56

border

Commandline tool to add a border around PNG images
Go
4
star
57

batchy.vim

A little plugin to perform batch operations on files
Vim Script
4
star
58

cantuse

List browsers in which a feature *won't* work
Go
3
star
59

confirm_quit.vim

Ask for confirmation before quitting Vim.
Vim Script
3
star
60

goatcov

Code coverage tool for Go
Go
3
star
61

bsdgrep

BSD grep from FreeBSD for Linux
C
3
star
62

zvalidate

Static validation for Go that returns parsed values
Go
3
star
63

autofox

Automatically configure Firefox
Go
3
star
64

tz

Go timezone convience library
Go
3
star
65

errors

Yet another errors package for Go
Go
3
star
66

wtff

frontend for some ffmpeg operations
Go
3
star
67

sqlbench

Run benchmarks on an SQL database
Go
3
star
68

zlog

Go logging library
Go
3
star
69

acidtab

Go package to print nicely aligned tables in the terminal
Go
3
star
70

git-stats

Aggregate statistics for git repos
Go
3
star
71

slog_align

Less "wall of text"-y slog handler
Go
3
star
72

aurgit

A simple way to manage AUR packages
Python
2
star
73

hubhub

Set of utility functions for working with the GitHub API.
Go
2
star
74

pg_info

Make it a bit easier to read the various pg_stat_* tables in PostgreSQL (WIP!)
Go
2
star
75

complete_email.vim

Allow completion of email addresses so you can use Vim as a basic "address book".
Vim Script
2
star
76

globedit.vim

Use globbing patterns for :edit, :tabedit, etc.
Vim Script
2
star
77

goathost

Shell
2
star
78

z18n

i18n library for Go
Go
2
star
79

RimWorld-RainingBlood

Example RimWorld mod
C#
2
star
80

ADVENT

Colossal Cave Adventure for modern systems, as close to the 1976 source as possible
Fortran
2
star
81

termfo

A terminfo library for Go
Go
2
star
82

jfmt

Format json, nicely
Go
2
star
83

spamdb-curses

Curses tools to interface with OpenBSD's spamdb(8), which is a part of spamd(8).
Python
1
star
84

json

encoding/json with patches
Go
1
star
85

zstripe

Set of utility functions for working with the Stripe API.
Go
1
star
86

imlib2-heif

Imlib2 plugin for libheif, allowing you to load HEIF, HEIC, and AVIF images (e.g. as used by iPhones)
C
1
star
87

operapass

Read opera password files (a.k.a. "the wand").
Python
1
star
88

markdown-wiki

Simple wiki.
Ruby
1
star
89

har

Read HAR ("HTTP Archive format") files
Go
1
star
90

nordavind

Web based audio player.
CoffeeScript
1
star
91

tpad.zsh

A little script to control some various things on my ThinkPad
Shell
1
star
92

zgo.at

zgo.at website
HTML
1
star
93

synfo.vim

Print information about Vim syntax highlighting and text properties
Vim Script
1
star
94

uni-wasm

WASM demo for uni
JavaScript
1
star
95

robots

Reproduction of the 1980 “classic” robots game for BSD UNIX written by Ken Arnold. You can play it in your browser at: http://arp242.net/robots/
CoffeeScript
1
star
96

toml-test-matrix

HTML
1
star