pm-abc123-1234567890Add this single line of code to your website’s <head> section, just before the closing </head> tag:
<script src="https://your-domain.com/pm-tracker.js" data-tracking-code="pm-abc123-1234567890"></script>
Replace:
https://your-domain.com with your PrivacyMetrics server URLpm-abc123-1234567890 with your actual tracking codeThat’s it! Your website is now tracked. Visit your dashboard to see real-time analytics.
Add to your index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Website</title>
<!-- PrivacyMetrics Tracking -->
<script src="https://your-domain.com/pm-tracker.js" data-tracking-code="pm-abc123-1234567890"></script>
</head>
<body>
<h1>Welcome to my website</h1>
</body>
</html>
</head>Or use a plugin like Insert Headers and Footers.
Add to public/index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<!-- ... other head elements ... -->
<!-- PrivacyMetrics -->
<script src="https://your-domain.com/pm-tracker.js" data-tracking-code="pm-abc123-1234567890"></script>
</head>
<body>
<div id="root"></div>
</body>
</html>
Add to pages/_document.js (or _document.tsx):
import { Html, Head, Main, NextScript } from 'next/document'
export default function Document() {
return (
<Html>
<Head>
{/* PrivacyMetrics Tracking */}
<script
src="https://your-domain.com/pm-tracker.js"
data-tracking-code="pm-abc123-1234567890"
/>
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
Add to public/index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<!-- ... other head elements ... -->
<!-- PrivacyMetrics -->
<script src="https://your-domain.com/pm-tracker.js" data-tracking-code="pm-abc123-1234567890"></script>
</head>
<body>
<div id="app"></div>
</body>
</html>
Add to src/index.html:
<!doctype html>
<html lang="en">
<head>
<!-- ... other head elements ... -->
<!-- PrivacyMetrics -->
<script src="https://your-domain.com/pm-tracker.js" data-tracking-code="pm-abc123-1234567890"></script>
</head>
<body>
<app-root></app-root>
</body>
</html>
Add to gatsby-ssr.js:
export const onRenderBody = ({ setHeadComponents }) => {
setHeadComponents([
<script
key="privacy-metrics"
src="https://your-domain.com/pm-tracker.js"
data-tracking-code="pm-abc123-1234567890"
/>,
]);
};
If your tracking API is on a different domain:
<script
src="https://your-cdn.com/pm-tracker.js"
data-tracking-code="pm-abc123-1234567890"
data-api-endpoint="https://api.your-domain.com/api/v1/track"
></script>
Enable debug mode to see tracking events in the browser console:
<script
src="https://your-domain.com/pm-tracker.js"
data-tracking-code="pm-abc123-1234567890"
data-debug="true"
></script>
This will log:
Note: Don’t use debug mode in production!
Track button clicks, form submissions, or any custom action:
// Track a button click
document.getElementById('signup-btn').addEventListener('click', function() {
window.PrivacyMetrics.trackEvent('signup_button_clicked', {
location: 'homepage_hero',
buttonText: 'Get Started'
});
});
// Track form submission
document.getElementById('contact-form').addEventListener('submit', function() {
window.PrivacyMetrics.trackEvent('contact_form_submitted', {
formType: 'contact'
});
});
// Track file download
document.getElementById('download-btn').addEventListener('click', function() {
window.PrivacyMetrics.trackEvent('file_downloaded', {
fileName: 'whitepaper.pdf',
fileSize: '2.5MB'
});
});
For Single Page Applications (React, Vue, Angular), manually track route changes:
// React Router
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
function App() {
const location = useLocation();
useEffect(() => {
if (window.PrivacyMetrics) {
window.PrivacyMetrics.trackPageView();
}
}, [location]);
return <div>...</div>;
}
Allow users to opt-out of tracking:
<button onclick="window.PrivacyMetrics.optOut()">
Opt-out of Analytics
</button>
<button onclick="window.PrivacyMetrics.optIn()">
Opt-in to Analytics
</button>
Check opt-out status:
if (window.PrivacyMetrics.isOptedOut()) {
console.log('User has opted out of tracking');
}
✅ We DO track:
❌ We DON’T track:
?data-debug=true to your script tag temporarily[PrivacyMetrics] Tracking event: pageviewIf your site uses CSP headers, add:
script-src 'self' https://your-domain.com;
connect-src 'self' https://your-domain.com/api/v1/track;
For maximum privacy and control, host the tracking script on your own domain:
pm-tracker.js from your PrivacyMetrics server/js/pm-tracker.js)<script src="/js/pm-tracker.js" data-tracking-code="pm-abc123-1234567890"></script>
Benefits:
Check:
Check:
PrivacyMetrics is privacy-focused and shouldn’t be blocked, but some aggressive blockers might block it. If needed:
pm-tracker.js to something generic like analytics.jsTrack multiple websites with different tracking codes:
Website 1:
<script src="https://your-domain.com/pm-tracker.js" data-tracking-code="pm-site1-123"></script>
Website 2:
<script src="https://your-domain.com/pm-tracker.js" data-tracking-code="pm-site2-456"></script>
window.PrivacyMetricsThe global API object available after the script loads.
trackPageView()
trackEvent(eventName, properties)
eventName (string): Name of the eventproperties (object): Custom propertiestrack(eventType, eventData)
eventType (string): Event typeeventData (object): Event dataoptOut()
optIn()
isOptedOut()
true if user has opted outgetSessionId()
getVisitorId()
Last Updated: February 3, 2026