Github currently doesn't offer a method to see visitor traffic patterns. The PATHS
API merely returns the top 10 most popular paths on your repository. There is no guarantee of coverage. So, what happens if you want to see whether location A
in your repository is more popular than location B
?. Only way that we've found is to insert an image who's number of loads can be counted.
This python script inserts a pixel image whos name corresponds to the location of the rendered readme in the repository.
This script was built and tested on Python 3.6/
This project is the code involved for counting the number of impressions per rendered readme view. Update it however you want to store the data. Currently it leverages Application Insights
as the data store.
So there are prep steps before running this tool:
- Go host the code from the folder above in a publically accessible location.
- Update the
HOSTNAME
variable to point at wherever your site is hosted. - Run the script against your repository
python <script_location> -d <target_directory> -i <rep_identifier>
Target Directory:
The top level directory that the tool will search below for all readme.rst
or readme.md
files.
Repo Identifier:
If this is run on multiple repositories, some way needs to be maintained to tell readmes apart when the requests are being fired from the same relative URL within each repository. The tool places this repo identifier
as a lead value before the relative URL.
Given the below repository structure:
<repo-root, located at C:/repo/cool-repo>
│ README.md
│
└───<folder1>
└───README.rst
└───<other files and folders>
Let's walk through an example usage. The repo id
used here will be cool-repo
.
/:> python <script_location> -d C:/repo/cool-repo -i cool-repo
With the sample repo structure above and the inputs provided, /README.md
and /folder1/README.rst
would be affected after the script run. A new image would appear in both of them.
For markdown, like /README.md
:
![Impressions](<your HOSTNAME>/api/impressions/cool-repo%2FREADME.png)
For restructured text, like /folder1/README.rst
:
.. image:: <your HOSTNAME>/api/impressions/cool-repo%2Ffolder1%2FREADME.png