portfolio-starter icon indicating copy to clipboard operation
portfolio-starter copied to clipboard

How would I add analytics?

Open ashleigharmitage opened this issue 4 years ago • 4 comments

How could I add google analytics to my site?

ashleigharmitage avatar Apr 24 '20 16:04 ashleigharmitage

Follow Google's basic instructions. For step 3 ("…add the tag right after the opening <head> tag on each page"), you'll want to add the code to the base layout file, which gets used for all site pages:

/_includes/layouts/base.njk

Let me know if any issues!

sambaldwin avatar Apr 27 '20 10:04 sambaldwin

If using Netlify for hosting then you can use their analytics add-on. It isn't free ($9/mo) but it's a good option, particularly since there's no code needed to set it up.

sambaldwin avatar Apr 27 '20 10:04 sambaldwin

another (free) option if using Netlify is to take advantage of their snippet injection. in fact, the documentation mentions analytics as a use case

Most analytics providers, retargeting services, and A/B testing services will give you an HTML snippet and ask you to add it to every page on your site. Netlify lets you do this without having to pollute the source code for the site with production specific analytics snippets.

zackseuberling avatar Jul 14 '20 18:07 zackseuberling

Very useful to know, thanks @zackseuberling!

sambaldwin avatar Jul 15 '20 03:07 sambaldwin