Skip to main content

The PreTeXt Guide

Section 29.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 4  and StatCounter 5 .
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 publication file (Section 26.1), see Subsection 44.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 publication 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; these looked like UA-6836004-1. Google has now switched to Google Analytics 4 and is exclusively using the form of a Google Tag ID/Measurement ID which will look similar to G-CQG9X37H61; you will need to upgrade your analytics if you used the older style tag. In any case your publication file would have an element under html like
<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.
You have attempted of activities on this page.
analytics.google.com/analytics/web/
statcounter.com/