SciNim / getting-started

Getting started with Nim for Scientific Computing
https://scinim.github.io/getting-started/
Creative Commons Zero v1.0 Universal
61 stars 6 forks source link

Add plausible analytics #28

Closed pietroppeter closed 3 years ago

pietroppeter commented 3 years ago

this adds plausible analytics to this site (same as in nimibook). This is done through my plausible account which has currently plenty of views to use before reaching next threshold (10K over all sites). If needed in the future I will upgrade to 100k as part of my planned effort to sponsor Nim, but I guess it will take a bit of time. Even though analytics is provided through my account, I have made them publicly visible and if anyone of the maintainers is interested I can invite them to join (so that you would be able to change settings).

Clonkk commented 3 years ago

I like the idea and your generosity is much appreciated !

Plausible is a good choice, but could analytics be something optional that we add through Nimibook DSL ?

On an unrelated note, @HugoGranstrom, netlify makes CI fails, I don't know why :laughing:

Run Sibz/github-status-action@v1.1.5
Error: Error setting status:
Resource not accessible by integration
Request object:
{
  "context": "Netlify preview",
  "description": "Waiting for build to finish",
  "state": "pending",
  "owner": "SciNim",
  "repo": "getting-started",
  "sha": "64dfd3a57a7a4d923f969df953cc1e6c1f801dc5",
  "target_url": ""
}
pietroppeter commented 3 years ago

Plausible is a good choice, but could analytics be something optional that we add through Nimibook DSL ?

what do you mean by optional? only on some pages and not others? we could provide a mechanism in every page to opt-in (default no analytics) or opt-out (default yes analytics), but I do not see a reason on why we would need to have it only on some pages.

pietroppeter commented 3 years ago

mmh, maybe I understand. You want something like: book.plausible_analytics = "scinim.github.io/getting-started"? it would need a change in Nimibook, but it looks fine to do it like that (in mdbook there is a similar mechanism for google analytics)

HugoGranstrom commented 3 years ago

I can only agree with Clonkk, we appreciate your generosity very much! 😄

On an unrelated note, @HugoGranstrom, netlify makes CI fails, I don't know why 😆

Ugh... It's about these bloody forks! 🤣 Basically, we can't do anything fancy in the valid workflow (like adding a pending status in this case) because it is run from the fork and lacks all kinds of permissions 🙃 I have reverted that change so it should run now. I have an idea for how we could make it work though, by creating a separate workflow that has elevated permissions that start at the same time as valid but all it does is create the pending status :P (A new commit to this PR should clear CI)

mmh, maybe I understand. You want something like: book.plausible_analytics = "scinim.github.io/getting-started"? it would need a change in Nimibook, but it looks fine to do it like that (in mdbook there is a similar mechanism for google analytics)

That's how I understood it as well.

Clonkk commented 3 years ago

mmh, maybe I understand. You want something like: book.plausible_analytics = "scinim.github.io/getting-started"? it would need a change in Nimibook, but it looks fine to do it like that (in mdbook there is a similar mechanism for google analytics)

I'm not sure which API would work best, but yeah it's pretty much what I had in mind.

(A new commit to this PR should clear CI)

I've tried restarting the CI to no avail. Why is a commit needed ? To generate a new hash ?

HugoGranstrom commented 3 years ago

I've tried restarting the CI to no avail. Why is a commit needed ? To generate a new hash ?

I'm pretty certain that when you re-run a workflow it uses the same exact file it used originally (it's cached, but interestingly enough the pr_preview which is called afterward isn't cached) so we have to push a new commit for it to use the updated valid.yml. CI is weird (:

pietroppeter commented 3 years ago

I'm not sure which API would work best, but yeah it's pretty much what I had in mind.

ok, I will make changes in nimibook and make a new commit here (later today or tomorrow)

pietroppeter commented 3 years ago

I leave a note down here on an alternative API:

book.hostUrl = "scinim.github.io/getting-started" # or https://scinim.github.io/getting-started
book.plausibleAnalytics = true

hostUrl could be something that makes sense in general and can be useful for other purposes (e.g. to create absolute urls, although not sure why they would be useful). In principle it could be also auto-detected for github repos (assuming they use github pages). There is a similar concept both in jekyll and hugo but unfortunately the name baseUrl is used in two different ways (this is why I am coming up with a different name), see https://www.freecodecamp.org/news/hugo-vs-jekyll-battle-of-static-site-generator-themes/

HugoGranstrom commented 3 years ago

Yes that seems like something that could be useful in other cases as well 👍

pietroppeter commented 3 years ago

ok, this should work now. Nimibook is updated upstream.

HugoGranstrom commented 3 years ago

Great! Thank you for your generosity and work 😄 Do you mind adding the link to see the statistics on the README? I see no reason not to be open about our traffic (if it's ok with you of course)

pietroppeter commented 3 years ago

The link is already there in the paragraph (after "publicly available")

HugoGranstrom commented 3 years ago

Oops sorry missed that 🙈 I'm content with merging this now

Clonkk commented 3 years ago

Yeah, this looks good.

Merging this then so #29 can be taken care of without conflicts

pietroppeter commented 3 years ago

do you confirm that you can see analytics? https://plausible.io/scinim.github.io%2Fgetting-started

HugoGranstrom commented 3 years ago

Yes can confirm, 6 unique visitors thus far :)

HugoGranstrom commented 3 years ago

Or wait, tried the link on my phone now and it gave me an error 🤔

pietroppeter commented 3 years ago

Or wait, tried the link on my phone now and it gave me an error 🤔

not sure, I am able to acess both desktop and mobile

HugoGranstrom commented 3 years ago

Seems like it was the Github app that formatted the url wrongly (the %2F was replaced by / for some reason). If I click it in the browser it works 👍