holoviz-dev / nbsite

Build a tested, sphinx-based website from notebooks
https://nbsite.holoviz.org
BSD 3-Clause "New" or "Revised" License
29 stars 13 forks source link

Add analytics extension with GoatCounter support #296

Closed maximlt closed 11 months ago

maximlt commented 11 months ago

Implements https://github.com/holoviz-dev/nbsite/issues/294

Inspired from the conda extension and adapted having in mind we should upstream it one day to the pydata sphinx theme.

In their conf.py HoloViz sites will have to register the extension nbsite.analytics and set:

nbsite_analytics = {
    'goatcounter_holoviz': True,
}

One issue I've seen in the generated HTML is that the app.add_js_file(None, body=...) call seems to be inserted twice. I don't think it's an issue with the code written in this PR, app.add_js_file(None, body=...) is called just once as far as I can see. Internal Sphinx issue? I don't know whether this is going to cause any problem or not in practice. This PR should build nbsite's dev site so we'll see immediately if we get data on GoatCounter's dashboard.

<script>
    window.goatcounter = {
        path: function(p) { return location.host + p }
    }
</script>
<script async="async" data-goatcounter="https://holoviz.goatcounter.com" src="_static/js/goatcounter.js?v=f53f84b8"></script>
<script>
    window.goatcounter = {
        path: function(p) { return location.host + p }
    }
</script>
maximlt commented 11 months ago

Actually the dev site built from this PR doesn't suffer from this double JS injection I described above. Not sure what's going on on my local system.

Source of the deployed site:

image
maximlt commented 11 months ago

Thanks for the review! I'm going to merge and tag.