JavaScript tracker
Use the installed browser script to track pages, custom actions, and known users.
Copy the single tracker tag from Website → Settings → Tracking. Its script URL, data-domain, and data-write-key are generated for your Website. Install it once in the shared HTML head. The installation guide shows HTML and Next.js App Router examples.
Automatic behavior
The script sets _gt_id, sends a pageview on load and pathname changes, and groups visits into sessions. It suppresses repeat views of the same path within 60 seconds. A valid gt_exp parameter on an Experiment link supplies experiment context.
Newly generated installation snippets include data-gt-batch="true". With this attribute, the tracker briefly groups pageviews and custom events (up to ten per request) and flushes when the page is left. An initial pageview uses a 100 ms flush timer, subject to browser timer delays. Identity and checkout calls are sent separately. Existing snippets without the attribute continue to work and send ordinary events individually; replace the snippet from Website settings to enable batching. The cookieless script follows the same batching behavior without persisting a browser retry queue.
Ordinary browser events use time-bearing IDs and can retry for up to 24 hours; older queued events are discarded. The collector also rejects stale event and batch IDs, so an offline tab cannot send yesterday's analytics as new usage. Identity and checkout calls retain their separate handling.
Browser calls
window.graytower("account_created", { plan: "pro" });
window.graytower("identify", { userId: user.id, email: user.email });Use a named custom event for actions you want in Goals or Funnels. identify needs a user ID or email. Before another account uses this browser, call window.graytower("reset") to start a new anonymous identity and session.
Call the JavaScript API after the tracker has loaded. If an app must call it during initial page setup, install the optional preload queue before the tracker. A deferred HTML script or Next.js afterInteractive script may execute after your app's early calls.
Reserved checkout call
The reserved checkout_started call accepts exactly one checkoutSessionId or paymentIntentId for payment matching. It describes a checkout attempt, not a successful payment. See Improve payment matching.
Avoid manually reusing another experiment's key. If the script is loaded twice, duplicate tracking and conflicting browser state can result. For accepted event rules and usage, see Custom events.