Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add visitor count and analytics to R blogdown > netlify housted website

I am creating my personal website (here) using R blogdown (using a Hugo template). The site is hosted on github and I managed get it to continously integrated with netlify.

I would like to keep track of some visitor analytics.

How can I add a visitor count and some sort of visitor analytics tool?

Can the Netlify be integrated with google analytics or some similar tool?

like image 272
LucasMation Avatar asked Dec 21 '17 03:12

LucasMation


2 Answers

The blogdown guide has a how-to section detailing how to incorporate Google Analytics for your blogdown page. The example in the documentation using one theme, Xmin, but should be transferable to other Hugo blogdown themes. I have followed it for my own blogdown site.

Add the following snippet to your code in layouts/partials/foot_custom.html that lives under the root directory of your page

{{ template "_internal/google_analytics.html" . }}

Then configure the googleAnalyticsfield in your sites config.toml with your GA credentials.

The blogdown author Yihui details these exact steps in this PR here.

like image 97
dshkol Avatar answered Sep 25 '22 01:09

dshkol


Disclaimer: I work for Netlify.

There are no built-in analytics or other visitor logging at present on our service, so google analytics is a good bet. The New Relic browser agent is another option you can use in the same way. They both count on browsers to run javascript and allow tracking, so the numbers they report should be taken with a grain of salt.

The intended path, though by no means the only one, is to place your GA tags or other code you need to inject into every html page into the injected snippets section on your Build & Deploy settings page.

Note that there is some advanced usage potential around deploy-time conditionals like Branch-dependent variables that isn't immediately obvious. You can see it demonstrated in this article on split testing (the conditionals are usable without split testing).

like image 42
fool Avatar answered Sep 23 '22 01:09

fool