msgbyte / tianji

Tianji: Insight into everything, Website Analytics + Uptime Monitor + Server Status. not only another GA alternatives
https://tianji.msgbyte.com/
Apache License 2.0
1.22k stars 65 forks source link

[Feature] Config a filter or ignore specified domains like 'localhost' #46

Closed shinyzhu closed 3 months ago

shinyzhu commented 3 months ago

I've been using tianji for a while.

Sometimes I need to develop and run the site locally but it tracked the visits that I don't need.

I'd like to request a feature to config a domain list to track.

Great thanks :)

moonrailgun commented 3 months ago

i get you mind. the best way is only inject track code in production build.

but i think we can ignore localhost request and add domain only checkbox in website config.

i will do it later. thanks for your suggestion

shinyzhu commented 3 months ago

It's already supported this after doing some discovery in the code. :D

Here is the solution:

You just put your tracking domains into the data-domains attribute of the tracker script.

<script async defer src="your-tracker.js" data-website-id="your-id" data-domains="yourname.com,www.yourname.com"></script>

Then it won't send payload to server when running on localhost or any different domains.

ref: https://github.com/msgbyte/tianji/blob/master/src/tracker/index.js#L26

moonrailgun commented 3 months ago

Oh thanks for your invest, i will add it into document