askides / aurora

Hate Cookies? Introducing Aurora, 100% Cookie-Free Open Website Analytics. Collect Anonymous Data. Make your Audience Happy Now!
576 stars 20 forks source link

Collect API call fails when user language is set to "de" #71

Closed hennedo closed 2 years ago

hennedo commented 3 years ago

Hey!

I'm using Firefox 89.0.2 on MacOS Everything worked fine while my language setting was set to "English (Canada)" navigator.language === "en-CA" When I set my language to "German" which correspondents to navigator.language === "de" it stopped working.

It's the https://auroraapi.example.com/v2/collect call that fails

statusCode  500
code    "23502"
error   "Internal Server Error"
message "insert into \"locales\" (\"local\", \"location\", \"name\", \"tag\") values ($1, $2, $3, $4) returning * - null value in column \"location\" violates not-null constraint"

Request body was

element "/"
fingerprint "c9dab441c9d31bd3f1fcc10a89daa9f0"
language    "de"
referrer    ""
seed    "1c070be13184f4086e42472a862b5f3c"
type    "pageView"

My guess would be, that the language parser does not like "de" and wants "de-DE"?

askides commented 3 years ago

Hello!

Tank you for your issue.

Yes, probably the locale parser does not have data for the de locale code, i will investigate this problem.

Probably is the case to set the db column nullable, in order to avoid future exceptions.

askides commented 3 years ago

Hello,

Please upgrade the api module to the 1.0.2 version.

I've implemented a bugfix.

Let me know if now it works.

askides commented 2 years ago

Hi @hennedo, any news?

hennedo commented 2 years ago

Sorry for replying late, I will have time on sunday to check if it's working :)

askides commented 2 years ago

Hello @hennedo, any news?

hennedo commented 2 years ago

Hey! It is working now as expected, with correct locale string like "en-CA" it shows up correct as English in Canada, with "de" it shows up as #ND. So data is collected and aurora works now as intended even with language tags that are not complete.

Reason for the delay is that I dug a little deeper to understand the core problem and that I wanted to present a solution better than "#ND". Sadly it's not that easy. The library is absolute correctly returning a null location, because there is no location Information in the tag "de". After some digging my first idea was just to check if there is a dash in the location tag and if not, simply extend the tag to tag = tag + '-' + tag. But this works only for 28 languages out of 229 which have a tag without dash. Although it would propably approximate a bit better than #ND..

On the other hand, the preferred browsing language is also just an approximation for the location, as a e.g. a German living in Canada might still prefer browsing in native language. Something like geolocation by IP might be more accurate but also uses more private data, which is propably not the goal of this project..

If you'd like me to make a PR for the tag = tag + '-' + tag (with check if it exists and so on), just hit me up

Thanks for the hotfix!

askides commented 2 years ago

Thank you,

Ideally, your idea is good, as you said, it works only in 28 languages but is a bit better improvements, so for me, the PR is ok.

A question about that: do you know the reason why some browsers show the 'non dashed' locale?

Another idea in my opinion is to replace #ND (which is pretty bad) with something like 'others', which I think is a more clean way. The problem, in this case, is that the 'other' keyword could be misunderstood with the group of all the minor locale cases, so maybe isn't the correct way to display the label.

What do you think about it?

Thank you!

askides commented 2 years ago

Closed due to API changing.