Tracking Setup
Add a single script tag to your website's <head> to start tracking AI traffic. The script is under 2KB gzipped, loads asynchronously, and automatically detects LLM referrals from ChatGPT, Claude, Perplexity, and 15+ other AI services.
Basic Installation
Add this snippet before the closing </head> tag on every page you want to track:
Basic Installation
<!-- AttractOS Tracking -->
<script>
(function(w,d,k){
w.aos=w.aos||{q:[]};
w.aos.k=k;
var s=d.createElement('script');
s.async=true;
s.src='https://attractos.com/t.js';
d.head.appendChild(s);
})(window,document,'YOUR_SITE_KEY');
</script>// Next.js (app/layout.tsx)
import Script from 'next/script';
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<Script id="attractos" strategy="afterInteractive">
{`(function(w,d,k){
w.aos=w.aos||{q:[]};
w.aos.k=k;
var s=d.createElement('script');
s.async=true;
s.src='https://attractos.com/t.js';
d.head.appendChild(s);
})(window,document,'YOUR_SITE_KEY');`}
</Script>
</head>
<body>{children}</body>
</html>
);
}# Astro (src/layouts/BaseLayout.astro)
---
const siteKey = import.meta.env.ATTRACTOS_SITE_KEY;
---
<html>
<head>
<script is:inline define:vars={{ siteKey }}>
(function(w,d,k){
w.aos=w.aos||{q:[]};
w.aos.k=k;
var s=d.createElement('script');
s.async=true;
s.src='https://attractos.com/t.js';
d.head.appendChild(s);
})(window,document,siteKey);
</script>
</head>
<body><slot /></body>
</html>
Replace YOUR_SITE_KEY with the key from your dashboard (format: ak_abc123xyz).
Framework-Specific Setup
WordPress
Add the script via your theme's functions.php or a plugin like "Insert Headers and Footers":
// Add to functions.php
function add_attractos_tracking() {
?>
<script>
(function(w,d,k){
w.aos=w.aos||{q:[]};
w.aos.k=k;
var s=d.createElement('script');
s.async=true;
s.src='https://attractos.com/t.js';
d.head.appendChild(s);
})(window,document,'YOUR_SITE_KEY');
</script>
<?php
}
add_action('wp_head', 'add_attractos_tracking'); Shopify
Add to your theme's theme.liquid file, inside the <head> section:
{% comment %} AttractOS Tracking {% endcomment %}
<script>
(function(w,d,k){
w.aos=w.aos||{q:[]};
w.aos.k=k;
var s=d.createElement('script');
s.async=true;
s.src='https://attractos.com/t.js';
d.head.appendChild(s);
})(window,document,'YOUR_SITE_KEY');
</script> Google Tag Manager
Create a Custom HTML tag with the script, triggered on All Pages.
What the Script Does
When loaded, the tracking script:
- Detects LLM referrals — Checks
document.referrerfor known AI services - Sends referral event — If from an LLM, sends a referral event with source and page path
- Stores visitor ID — Generates a random ID stored in localStorage for conversion attribution
- Exposes tracking API — Provides
window.aos.track()for custom conversion events
The script does not:
- Use cookies
- Track mouse movements or keystrokes
- Collect personal information
- Slow down page load
Verify Installation
- Add the script to your site and deploy
- Open your site in a browser
- Open DevTools → Network tab
- Filter by "attractos" or "t.js"
- You should see:
t.jsloaded successfully (200 status)- POST to
/api/tif you came from an LLM referral
Test with a Real Referral
To test LLM referral detection:
- Open ChatGPT with web browsing enabled
- Ask it to summarize a page on your site (provide the URL)
- Click the citation link in ChatGPT's response
- Check your AttractOS dashboard — you should see the referral within seconds
Next Steps
Now that tracking is installed:
- Set up conversion tracking to measure business impact
- Learn about bot detection to understand AI visibility
- Add Cloudflare Logpush for server-side bot data
Frequently Asked Questions
Does the script work with single-page applications (SPAs)?
Yes. The script automatically detects page navigation in SPAs built with React, Vue, Next.js, Nuxt, and similar frameworks. LLM referral detection happens on initial load.
Will the script block page rendering?
No. The script loads asynchronously and executes after your page content has loaded. It has zero impact on First Contentful Paint (FCP) or Largest Contentful Paint (LCP).
Do I need to handle GDPR consent?
AttractOS doesn't use cookies or track individual users, so it generally doesn't require consent banners. However, consult your legal counsel for your specific situation.
Can I verify the script is working?
Yes. Open your browser's DevTools Network tab and look for requests to
attractos.com/api/t. You can also visit your site from ChatGPT (using web browsing) and check your dashboard for the referral.