To keep track of traffic to blogdown (hugo-based) webpages in google analytics, follow the steps below

See Google’s instructions here. Briefly

  1. Sign in to your Analytics account.
  2. Click Admin.
  3. Select an account from the menu in the ACCOUNT column.
  4. Select a property from the menu in the PROPERTY column.
  5. Under PROPERTY, click Tracking Info > Tracking Code.Your Tracking ID is displayed at the top of the page.

Copy the global site tag, which is several lines of code that you need to paste into each webpage you want to measure. Below is the code for tracking predictdb.org

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-61894206-2"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-61894206-2');
</script>

  1. Copy the code above to the site’s layout head_custom.html file. For example for predictdb website, the file is found in https://github.com/hakyimlab/web-predictdb/blob/main/layouts/partials/head_custom.html.
  2. Paste it immediately after the <head> tag on each page of your site.

Reuse

Text and figures are licensed under Creative Commons Attribution CC BY 4.0. The source code is licensed under MIT.

Suggest changes

If you find any mistakes (including typos) or want to suggest changes, please feel free to edit the source file of this page on Github and create a pull request.

Citation

For attribution, please cite this work as

Haky Im (2021). Tracking the traffic to webpages. ImLab Notes. /post/2021/07/26/tracking-the-traffic-to-webpages/

BibTeX citation

@misc{
  title = "Tracking the traffic to webpages",
  author = "Haky Im",
  year = "2021",
  journal = "ImLab Notes",
  note = "/post/2021/07/26/tracking-the-traffic-to-webpages/"
}