Get this embeddable visitor badge for free for your GitHub profile or any markdown file.
- GitHub Account. (https://github.com)
- Vercel Account. (https://vercel.com)
- Create a free distributed Redis cache on Vercel using this link.
- Press the Deploy button to take your badge to the cloud!
-
In Vercel create project screen, you need to fill in all environment variables related to Redis. If you did step 1, you must already have them. You can bring your own Redis as well since the client used in the badge code is a generic Redis client which can connect to any datastore that supports Redis protocol. If you're using Vercel KV, make sure to set
REDIS_USE_TLS
totrue
andREDIS_DATABASE
to0
. -
After the deployment is complete, you should have a url of the deployment. It must be something like this
https://<your-slug>.vercel.app
. Note this down for the next step. -
Paste the following markdown snippet inside your README.md file of your GitHub profile or any markdown file where you want to track visitors.
![visitors](<url-from-step-4>/api/count)
- And Voila! You should be able to see the badge appear instantly. Since this is a global edge function, your users should also see the badge appear almost instantly irrespective of their location on the globe. The process is fast also because the count of visitors is stored in a distributed in-memory cache.
The look and feel of the badge can be customised by providing a set of query params inside the markdown snippet as described in the below picture.
- Install Golang
1.20.4
if not done previously. - To run the project locally, clone it in your machine.
- Then run
go mod tidy
. - The project is bundled with an HTTP server as well, to start it, run
# Replace "REDIS_HOST_URL" and "REDIS_PORT" with real values.
REDIS_HOST="<REDIS_HOST_URL>" REDIS_PORT=<REDIS_PORT> go run cmd/markdown-visitor-badge/main.go
- Visit
http://localhost:8080
to see your badge!
MIT.