Skip to main content

Section 27.7 Analytics

PreTeXt makes it as easy as possible to have services provide data about visitors to the HTML version of your book. We support Google Analytics 1  and StatCounter 2 .

analytics.google.com/analytics/web/
statcounter.com/

In each case, use is similar. Begin at the service's site and follow their instructions for enabling data collection for your book's site. We will not document those instructions here. Do not copy the identification numbers from another project—be sure to obtain your own for your project. When completed, you can request (or will be shown) sample Javascript code to add to pages on your site. Except, PreTeXt is going to do that part for you. You only need to provide the unique identifiers used by the service that identify your project. Because these sign-ups are dependent on your site, this is a publisher activity, and hence configured with the publisher file (Section 26.1), see Subsection 40.4.1 for details.

StatCounter uses two identifiers, a project ID and a security code. Do not copy the identification numbers from another project—be sure to obtain your own for your project. You can find them in your “Project Config” under “Settings”. Or the code provided will contain lines such as

var sc_project=11538430;
var sc_invisible=1;
var sc_security="72e1390a";

In which case your publisher file would have an element under html like

<analytics statcounter-project="11538430"
           statcounter-security"72e1390a"/>

Google Analytics comes in several flavors. We once supported Classic and Universal, but no longer, so we do not provide documentation here. For the replacement, Google Global Site Tag is a single ID. Do not copy the identification numbers from another project—be sure to obtain your own for your project. Google once called this a tracking ID, which may also be called a property ID. An example looks like UA-6836004-1. Google is also using a Meaurement ID which might look similar to G-CQG9X37H61. In either case your publisher file would have an element under html like

<analytics google-gst="UA-6836004-1"/>

or

<analytics google-gst="G-CQG9X37H61"/>

If you use both services, you can elect to use just one <analytics> element with several attributes.

We would be happy to provide support for additional major services. Just make a feature request.