Predictive Prefetching Demo
An example site showing how to do predictive prefetches with 11ty.
1. Clone this repository:
git clone firstname.lastname@example.org:shortdiv/cant-dutch-this.git my-first-predictive-prefetch
2. Navigate to the directory
Specifically have a look at
.eleventy.js to see if you want to configure any Eleventy options differently.
3. Install dependencies
npm install OR yarn
4. Edit _data/metadata.json
5. Run Eleventy
npm run build OR yarn build
Or build and host locally for local development
npm run serve OR yarn serve
Or build automatically when a template changes:
npm run watch OR yarn watch
Or in debug mode:
DEBUG=* npx eleventy
Create Your Credentials
Create a Service Account
Go to the Credentials page in the Google APIs console.
If you don't have an existing project, click "Create" to create a new project. Otherwise, select an existing project from the project dropdown.
Select "Service Account key" from the "Create credentials" dropdown.
Fill out the form for creating a service account key:
Service account dropdown: Select "New Service Account". Service account name: Create a service account a name. Role: Select "Service Accounts" > "Service Account User". Service account ID: Leave as is. Key type: Select P12 key. Click Create.
Setup Your Private Key
Note the private key password, you'll need this when you're converting your password to a pem file.
Move this key into the root directory for this project, outside of /src.
Generate a *.p12 certificate by running this command from the directory for this project:
$ openssl pkcs12 -in *.p12 -out key.pem -nodes -clcerts
You now need to add this service account to GA for the proper permissions.
In your GA account, create a new user and add the necessary permissions.
Add a new user. (Admin > User Management > + > Add New Users) Email Address: email@example.com.
Permissions: Select "Read & Analyze."
Note that you may need to Enable the Google Analytics Reporting API in your project
Configure env vars
We'll need to now configure our env variables. To do this in 11ty, we'll lean on nodeenv, which should alr be a dependency in this project. To take advantage of this, add
SERVICE_ACCOUNT to a .env file in your root dir. You can find these values in the view column of the accounts dropdown in GA.