Install Linqry on Angular
To add Linqry to an Angular app, paste the two-line snippet into the `<head>` of `src/index.html`. Angular Router navigations are recorded as page views automatically, so you only write code for custom events.
Updated · 2 min read
Install in src/index.html
- Create the site in Linqry
Start a free trial, add your production domain and copy the snippet from the Install page.
- Paste the snippet into index.html
src/index.htmlis the page served to every visitor. The Angular CLI adds your bundles to it at build time, and leaves tags you add yourself in place. Put the snippet inside<head>.<!-- src/index.html --> <!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title>My app</title> <base href="/" /> <script>window.linqry=window.linqry||function(){(window.linqry.q=window.linqry.q||[]).push(arguments)}</script> <script defer data-website-id="YOUR_SITE_ID" data-domain="yourdomain.com" src="https://linqry.com/t.js"></script> </head> <body> <app-root></app-root> </body> </html> - Build, deploy and verify
Run
ng build, deploy, then open the live app and visit a few routes. Realtime in Linqry shows each route as apageviewin the live event stream.
Don't add the tracker to the scripts array in angular.json. Keep it as a tag in index.html, so it loads from linqry.com with its data-* attributes on the tag where the tracker reads them.
Angular Router: path and hash strategies
By default the Angular Router uses PathLocationStrategy, the "HTML5 pushState" style, so URLs look like /settings/billing. The tracker wraps history.pushState and replaceState and listens for popstate, so every router navigation is a page view and the time spent on the previous route is reported when it's left. You don't need to subscribe to NavigationEnd.
If you bootstrap with provideRouter(routes, withHashLocation()), or provide HashLocationStrategy, routes live in the URL fragment (/#/settings/billing). Add data-hash-routing so the tracker treats hash changes as navigations:
<script defer data-website-id="YOUR_SITE_ID" data-domain="yourdomain.com" data-hash-routing src="https://linqry.com/t.js"></script>
Leave internal routes out
Many Angular apps mix a public marketing area with signed-in admin screens. If you only care about the public part, list the routes to skip in data-exclude, separated by commas, with * as a wildcard. Nothing is sent from matching paths, not even custom events.
<script defer data-website-id="YOUR_SITE_ID" data-domain="yourdomain.com" data-exclude="/admin/*,/internal/*" src="https://linqry.com/t.js"></script>
Custom events from components
Add a declaration so TypeScript knows about window.linqry (put it in a .d.ts file that your tsconfig includes), then call it from component methods:
// linqry.d.ts (anywhere your tsconfig includes)
export {};
declare global {
interface Window {
linqry?: (
event: string,
props?: Record<string, string | number | boolean>,
revenueCents?: number,
) => void;
}
}import { Component } from "@angular/core";
@Component({
selector: "app-pricing-cta",
template: `<button (click)="choosePlan('team')">Choose Team</button>`,
})
export class PricingCtaComponent {
choosePlan(plan: string) {
window.linqry?.("plan-selected", { plan });
}
}If you render on the server with Angular SSR, window doesn't exist there. Event handlers like the one above only run in the browser, so they're safe; code that runs during rendering should check isPlatformBrowser first. For simple click tracking, data-linqry-event="name" on an element works with no TypeScript at all. See custom events for naming rules and limits, and funnels for using events as conversion steps.
Local development and your own visits
ng serve runs on localhost, and Linqry ignores events from localhost, so development traffic never reaches your stats. Staging hostnames are rejected unless you add them under Additional hosts in site Settings. To exclude your own browser on production, run this once in its console on your live site:
localStorage.setItem('linqry_ignore', 'true')Troubleshooting
- Only the first page counted? Check whether the app uses hash URLs (
/#/). If it does, adddata-hash-routing. - Nothing at all? Look at the deployed
index.htmlto confirm the snippet survived the build and the site ID matches the Install page. - Strict Content-Security-Policy? Allow
https://linqry.cominscript-srcandconnect-src. The inline queue stub also needs to be allowed, for example with a nonce or hash.
Frequently asked questions
Is there an Angular module or service for Linqry?
No. Linqry has no Angular package. The snippet in index.html records page views, and window.linqry covers custom events; wrap it in your own small service if you prefer dependency injection.
Does it work with Angular SSR and prerendering?
Yes. The snippet is part of the index.html template, so server-rendered and prerendered pages include it, and the tracker runs once the page reaches the browser.
Sources
- Angular: Workspace and project file structure (src/index.html) (checked Nov 9, 2026)
- Angular: Common routing tasks (location strategies) (checked Nov 9, 2026)
- Angular: withHashLocation API (checked Nov 9, 2026)
Related
Paste the snippet into index.html in a Vite or other React SPA. React Router navigations are tracked as page views.
Add the snippet to index.html in a Vite-based Vue app. Vue Router navigations count as page views, including hash mode.
Send events from JavaScript or plain HTML attributes — plus the events Linqry records for you automatically.
Build a funnel from any custom events or URL paths and see how many visitors reach each step and where they drop off.
Start measuring your Angular site
No card required · 30-day trial · No cookies