ihucos / counter.dev

Web Analytics made simple

Home Page:https://counter.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ability to define referrer or a website

syabro opened this issue · comments

I've an electron app and it doesn't have a referrer. How can I use counter.dev?

I don't know how exactly electron works but I'd imagine that the "Sources" section would be just empty. The browser type tracking might also not make sense. The rest could be useful metrics. So I'd say you can just use it with limiations.

@ihucos I got 400 from your server because of the empty referrer :(

I see. In the code empty referrers should just be ignored and not raise an error (The err variable is ignored, should be called _ actually for better readability)

https://github.com/ihucos/counter.dev/blob/master/backend/endpoints/track.go#L101

So it must be something else I guess. Are you able to provide me with a minimal example. That would be a curl or similar request that causes the 400 response code.

curl 'https://t.counter.dev/trackpage' \
  -H 'authority: t.counter.dev' \
  -H 'accept: */*' \
  -H 'accept-language: en-GB' \
  -H 'content-type: application/x-www-form-urlencoded;charset=UTF-8' \
  -H 'sec-ch-ua: "Not:A-Brand";v="99", "Chromium";v="112"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "macOS"' \
  -H 'sec-fetch-dest: empty' \
  -H 'sec-fetch-mode: no-cors' \
  -H 'sec-fetch-site: cross-site' \
  -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) presync/0.1.0 Chrome/112.0.5615.87 Electron/24.1.2 Safari/537.36' \
  --data-raw 'id=fc040caa-d114-4925-9cf2-cda6fbfcaacc&page=%2FVolumes%2Fcode%2Fapps%2Fpresync%2Fpresync%2Fclient%2Fdist%2Fmac-arm64%2FPresync.app%2FContents%2FResources%2Fapp.asar%2Fout%2Frenderer%2Findex.html' \
  --compressed

says
Origin header can not be empty, not set or "null"%

Also track looks good, but I don't see any of them in the dashboard

curl 'https://t.counter.dev/track?referrer=&screen=2560x1707&id=fc040caa-d114-4925-9cf2-cda6fbfcaacc&utcoffset=7' --compressed

Sorry for the late reply. I see.

When counter.dev receives a tracking request it takes the domain name that should be tracked from the "Origin" header. There could be two possible solution.

  1. Add in a feature to specify the domain explicitly when including the tracking script as data-domain tag attribute. Pass that to the track request in the tracking script.

  2. Make the electron app behave like more common browsers.

Can we try number two. I never worked with Electron but made ChatGPT to spit out this code to manually add in the required Origin header.

const { app, session } = require('electron');

app.whenReady().then(() => {
  session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => {
    details.requestHeaders['Origin'] = 'https://your-app-origin.com'; // Set your app's origin here
    callback({ cancel: false, requestHeaders: details.requestHeaders });
  });
});

Would an approach in this direction make sense?

@ihucos thanks!
I solved it by the different aproach - loading html + css from the server, so it has a origin

I see. Thank you very much for the info.