Skip to content
xcsoft edited this page Oct 16, 2024 · 3 revisions

中文文档

Quick usage

<script defer src="https://busuanzi.9420.ltd/js"></script>

Total page views: <span id="busuanzi_page_pv"></span> times
Total visitors: <span id="busuanzi_page_uv"></span> people
Total site views: <span id="busuanzi_site_pv"></span> times
Total site visitors: <span id="busuanzi_site_uv"></span> people

If you're using my deployed demo, just include https://busuanzi.9420.ltd/js directly in your site.

Compared to the original Busuanzi, you may need to modify the tag IDs. You can continue reading the optional parameters below.

Optional Parameters

Attribute Default Value Description
data-api http://127.0.0.1:8080/api The API address for Busuanzi
pjax None Whether to listen for pjax changes
data-prefix busuanzi Tag prefix

Ex:

On websites that enable pjax technology, you can add the pjax attribute to the js tag to automatically update page counts when switching pages:

<script defer pjax src="https://busuanzi.9420.ltd/js"></script>

You can use the data-api attribute to specify the backend API endpoint:

<script defer data-api="https://busuanzi.9420.ltd/api" src="https://busuanzi.9420.ltd/js"></script>

Unlike the original version, we've removed the value characters from the HTML IDs for brevity, but you can still maintain compatibility by specifying the data-prefix attribute:

<script defer data-prefix="busuanzi_value" src="https://busuanzi.9420.ltd/js"></script>

Counting Method

For page_view (site visits), it increments by one for each visit.

For user_view (visitor count), it determines based on the user's browser UserAgent and IP address.

To prevent duplicate counting of visitors, after a user visits the site for the first time, we will write a signed key into the browser's local storage to mark the user's identity.

Other

Unlike the original Busuanzi, I chose not to use JSONP. It seems that some browsers have implemented stricter same-origin policies, which may cause issues in certain browsers.

I opted for a POST request to the backend, along with an x-bsz-referer request header to determine the current URL.

All information is stored using MD5.

Clone this wiki locally