Installation guides
Lovable
Add ProductLense to an app built with Lovable by pasting one prompt, then check the generated index.html has both tags unchanged.
Lovable writes the code for you, so the install is a prompt. Lovable generates a Vite and React app, where the script belongs in the head of index.html. The prompt asks for the exact tags, unchanged, because an AI that "improves" the tag can break it. Building with something else? See Bolt, v0 or Replit.
Replace SITE_ID in the prompt with the id from Settings → Sites in the ProductLense dashboard before you send it.
The prompt
Add ProductLense analytics to this project. In index.html, inside <head>, add these two tags exactly as written, before any other script:
<script>window.productlense=window.productlense||function(){(window.productlense.q=window.productlense.q||[]).push(arguments)}</script>
<script defer data-site="SITE_ID" data-scroll="true" data-clicks="true" src="https://api.productlense.app/a.js"></script>
They record each page, how far people scroll and what they click. Do not change the tags, do not add type="module", do not import the script from JavaScript, and do not install any package. After a user signs in, call window.productlense?.('identify', user.id, { email: user.email, name: user.name }) once with the signed-in user's id. Then add window.productlense?.('event', name, props) at the actions that matter, 8 to 15 in total: signup_completed, each onboarding step, the first use of the main feature, checkout_started, upgrade and cancel clicks and similar. Names are lower-case words joined with underscores; props are a small flat object with no emails, names or tokens. If the project creates checkouts (Stripe, Lemon Squeezy, Polar, Dodo Payments, Paddle or Razorpay), read the visitor id with window.productlense('visitorId', callback) when the checkout starts and store it on the checkout as metadata pl_visitor_id. Finish with a list of the events you added and where each fires, and whether checkouts carry the visitor id.Check what the AI wrote
Open index.html and confirm:
data-siteholds your real site id, notSITE_ID.- The
srcis exactlyhttps://api.productlense.app/a.js. - The tag has no
type="module"and is not imported from a.tsor.tsxfile. The script reads its settings from its own tag, which only works for a classic script.
Lovable previews your app on its own domain. Add your published domain to the site's hostnames in the ProductLense dashboard; visits from the preview domain are rejected unless you add it too.
Claude Code, Codex or Cursor
If your code lives in a repository, give a coding agent this prompt instead. During setup the ProductLense dashboard detects your framework, fills in your site id, names the exact file for that framework and offers a one-line claude or codex command, so you rarely need to edit it by hand.
Add ProductLense analytics to yoursite.com. It runs on Static HTML. There are four steps and each one feeds a report in the ProductLense dashboard, so do all four.
Step 1: install the script, with scroll depth and clicks on.
In the <head> of every page, add these two tags exactly as written, before any other script, keeping data-site, data-scroll, data-clicks and src unchanged:
<script>window.productlense=window.productlense||function(){(window.productlense.q=window.productlense.q||[]).push(arguments)}</script>
<script defer data-site="SITE_ID" data-scroll="true" data-clicks="true" src="https://api.productlense.app/a.js"></script>
data-scroll records how far down each page people scroll and data-clicks records what they click, by its text. The drop-off report and Lens read both.
Rules:
- Add it once. If a script with data-site="SITE_ID" or a src ending in /a.js is already there, add data-scroll="true" and data-clicks="true" to it if they are missing and leave the rest as it is.
- Keep the one-line queue stub before the script tag when the snippet has one.
- Do not turn the tags into a module, a wrapper component or an npm import, and do not install any package.
Step 2: identify signed-in users.
Wherever the app knows who the user is (after signup, after login, and on page load for a signed-in user), call once per page:
window.productlense?.('identify', user.id, { email: user.email, name: user.name })
The first argument is the user's stable id from the database, not the email. Without this call ProductLense cannot credit payments to the channel that brought the customer.
Step 3: track the steps people take toward paying.
These feed funnels and the drop-off report, which shows how often a visit ends right after each one. Read the codebase and find where important activity happens: signup and login, each onboarding step, the first use of the main feature, invites, pricing views, checkout start, upgrade and cancel clicks, plan changes, exports and other actions the owner would want in a funnel. Add window.productlense?.('event', name, props) at each, 8 to 15 events in total, not every click.
- Names: lower-case words joined with underscores, for example signup_completed, checkout_started, project_created. Letters, digits, spaces, underscores and hyphens only, up to 64 characters. Reuse one name wherever the same action happens.
- Send completion events after the action has succeeded (the request returned), and click events on the click. On plain HTML elements, data-pl-goal="checkout_started" (with data-pl-goal-plan="growth" for a prop) sends the event with no JavaScript.
- Props: a small flat object under 2 KB, such as { plan: 'growth', from: 'pricing' }. Never put emails, names, passwords, tokens or free text in props.
- Browser code only, always with optional chaining (window.productlense?.) so server rendering and tests never fail. In TypeScript, declare window.productlense once as (...args: unknown[]) => void. Do not add a wrapper library or an npm package. If the app already tracks events with another tool, mirror those calls instead of inventing new ones.
Step 4: put the visitor id on checkout.
If this codebase creates checkouts or payment links (Stripe, Lemon Squeezy, Polar, Dodo Payments, Paddle or Razorpay), read the visitor id in the browser when the checkout starts:
const visitorId = await new Promise((resolve) => (window.productlense ? window.productlense('visitorId', resolve) : resolve('')));
Send it with the request that creates the checkout and store it on the checkout as metadata pl_visitor_id; on a Stripe Checkout Session also set client_reference_id. Read it at checkout time, never from storage, because it changes every day. If the codebase creates no checkouts, skip this step. Details: https://productlense.app/docs/revenue/checkout-visitor-id
Then run the site locally with data-dev="true" added to the script tag for the check only (nothing is sent from localhost without it), open it, and confirm the browser sends a request to https://api.productlense.app/api/e when the page loads and again when one of the new events fires; then remove data-dev. Finish with a short list: the events you added, each with its file and the moment it fires; where identify is called; and whether checkouts now carry the visitor id (or that this codebase creates none).Verify your installation
- Publish or deploy the app, then open the published URL in a normal browser window.
- Open the Live page in the ProductLense dashboard. Your visit appears within a few seconds.
- In the browser's developer tools, the Network tab shows a
POSTtohttps://api.productlense.app/api/ewith status204.
If you export the project and run it on localhost, nothing is sent unless you add data-dev="true" to the tag. Ad blockers in your own browser may block the request. If the visit does not appear, follow Verify your installation.