Everything you need to integrate Begins Insights into your website and applications.
Add this script to your website, just before the closing </body> tag:
<script>
(function() {
fetch('https://insights.begins.site/api/track', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
id: 'visitor_' + Math.random().toString(36).substring(2) + Date.now(),
page: window.location.pathname,
referrer: document.referrer || 'direct'
})
}).catch(console.error);
})();
</script>
Track a page view or event.
fetch('/api/track', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
id: 'visitor_123',
page: '/home',
referrer: 'google.com'
})
})
Get analytics data.
fetch('/api/track')
.then(response => response.json())
.then(data => console.log(data))