Add CLItrail to GitBook
Where the CLItrail tag goes in GitBook, in its own idiom, with the consent, CSP and client-side routing details and how to check it works.
#Where the tag goes
Edit Not possible on GitBook-hosted pages: use a page on your own site. Put the tag on every page that shows your install command; site-wide is best, after your existing analytics tags.
<head>
<meta charset="utf-8" />
<!-- …your analytics tags first -->
<script defer src="https://YOUR_SERVICE/browser.js" data-website="YOUR_WEBSITE_ID"></script>
</head>
#Only after consent
Use the loader in place of the tag: nothing from CLItrail loads until startClitrail() runs. Load the loader before your consent manager's script and call startClitrail() from the manager's accept callback (most managers also run it on later visits once a choice is stored; check yours). Use the marketing category when installs go to Google Ads, Meta, TikTok or X Ads, and the analytics category when they only reach GA4 or your webhooks.
Consent loader
// Loads CLItrail only after the visitor agrees. Call startClitrail() from your
// consent manager's "accepted" callback; nothing is fetched or stored before that.
window.startClitrail = () => {
if (document.getElementById('clitrail')) return;
const tag = document.createElement('script');
tag.id = 'clitrail';
tag.src = 'https://YOUR_SERVICE/browser.js';
tag.dataset.website = 'YOUR_WEBSITE_ID';
document.head.append(tag);
};
<head>
<meta charset="utf-8" />
<!-- …your analytics tags first -->
<script defer src="/clitrail-consent.js"></script>
</head>
#Client-side routing
Follow the guide for the framework your own install page is built with.
#Content Security Policy
Set it on your own site, where the tag runs: add https://YOUR_SERVICE to script-src and connect-src, and blob: to worker-src (only Safari before 26 needs that one).
script-src 'self' https://YOUR_SERVICE;
connect-src 'self' https://YOUR_SERVICE;
worker-src 'self' blob:;
#Verify it works
- Deploy your own install page.
- Open a page with the tag in Chrome or Firefox (accept analytics first if you gate CLItrail on consent), open the developer console and run
await InstallAttribution.ready. It resolves to{ ok: true, urlId, hasAnalyticsContext, expiresAt }. - In the CLItrail dashboard, open Visits & identities: the visit is listed.
- Anything else names the cause:
disabled(no consent yet, ordata-enabled="false"),opfs_unavailable(the page is not served over https or from localhost),Error(the service refused the visit: add the page's origin, including a development origin such ashttp://localhost:3000, under Settings → Additional domains). IfInstallAttributionis undefined, the tag did not load: check the Network tab and your Content-Security-Policy.
Then run your installer on the same computer and check Install events, or run the hook with --doctor.
#Notes
- GitBook does not let you add your own scripts to a published site, including Google Tag Manager, and custom GitBook integrations cannot inject scripts either (only GitBook's own integrations can).
- Put the page that shows your install command on a site you control, add the tag there with any guide on this list, and link to it from GitBook.
GitBook documentation: gitbook.com/docs/manage-your-site/install-an-integration
Using other install paths or destinations? The setup generator puts this snippet together with your hooks and destination checklist.