cycool29's blog



“Programmer: A machine that turns coffee into code.”

Subscribe via RSS

Subscribe via Email

14 February 2022

Pro way of making a GitHub Profile views-counter

Read on Medium

Read on Dev.to

5 mins read

by cycool29


Table of Contents


You might want to see how many times your GitHub profile has been viewed. It reflects your popularity on GitHub.

There are many tools for similar purposes on GitHub, but here, we are using Bitly link.

Before starting, you will need to create a Profile README. GitHub Docs has nice documentation on it.

Step 1: Create Bitly Link

Create button

Create link

Save

Now, you’ve got your Bitly link set up!

Step 2: Embed to your GitHub Profile

Now your GitHub Profile Counter is done! You can check how many people land on your profile at bitly.com.

Bonus: Show GitHub Profile Views badge

You may notice my GitHub Profile has a GitHub Profile Views badge.

GitHub Profile Views

Here is how to create it.

DevTools

name: Update Profile Views

on:
  schedule:
    - cron: "*/5  * * * *"
  workflow_dispatch:
  push: { branches: ["main"] }

env:
  COLOR: 00ff00

jobs:
  update-profile-views:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Update Profile Views
        run: |
          VIEWS="$($ 2>/dev/null | jq | grep -B 2 '"hash": "YOUR_HASH"' | head -n 1 | grep -o "[1234567890]*")"          
          echo '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="214" height="20" role="img" aria-label="$&apos;s GitHub Profile Views: 259"><title>$&apos;s GitHub Profile Views: 259</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="214" height="20" rx="3" fill="#$"/></clipPath><g clip-path="url(#r)"><rect width="183" height="20" fill="#000"/><rect x="183" width="31" height="20" fill="#4c1"/><rect width="214" height="20" fill="url(#s)"/></g><g fill="#$" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="925" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="1730">$&apos;s GitHub Profile Views</text><text x="925" y="140" transform="scale(.1)" fill="#$" textLength="1730">$&apos;s GitHub Profile Views</text><text aria-hidden="true" x="1975" y="150" fill="#$" fill-opacity=".3" transform="scale(.1)" textLength="210">259</text><text x="1975" y="140" transform="scale(.1)" fill="#000" textLength="210">259</text></g></svg>' | sed "s/259/$VIEWS/g" > profile-views.svg
          git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git config user.name "github-actions[bot]"
          git pull
          git add -A
          git diff-index --quiet HEAD || git commit -m "Update profile views to ${VIEWS}"
          git push
[<img src="https://raw.githubusercontent.com/[your-github-username]/[your-github-username]/main/profile-views.svg" height="50"/>](https://github.com/[your-github-username])

Well done! You should see a beautiful badge in your GitHub profile!

How it works

How a Bitly link count profile views?

The principle is very simple.

We made the link in a img tag. Hence, everytime when users loads your profile page, GitHub will requests to the link. Although actually it is not an image, the request is still recorded in the Bitly server.

How the badge is generated?

As of the Profile Views badge, we just created a GitHub workflow to automatically update our profile views from Bitly and create a SVG image in the profile repository root every five minutes (it is not exactly five minutes, it runs about 2 to 3 times each hour). And we just simply embed the image in our profile README.

tags: github - profile - readme - tutorial


Share this article:

Subscribe to our newsletter

Get the highlights in your inbox when there is a new post.

Email Address:

First Name:

Last Name: