What's the best practice for adding Google Analytics to a project hosted with GitHub pages?

967 Views Asked by At

I have a project hosted on GitHub that I would like to add tracking with Google Analytics to. It is a public repository and the live app is served directly from the master branch. Are there any security (or other) issues with putting the GA tracking snippet directly inside the index.html ?

1

There are 1 best solutions below

2
On

The unique identifier (UA) for your Google Analytics account must be present on a website. You can find them on almost every website by going to "View Source" and looking at the google_analytics_id variable. Here's an example from Kickstarter.com:

var analytics_vars = {
    google_analytics_id : "UA-7621056-1",
    logged_in : "true",
    social_user: "true"
  }

Google recommends embedding this in </head> (source)