const url = 'https://api.getdx.com/events.track'; const apiKey = 'XXXXXXXXXXXXXXXXXXXXX'; // Make sure to replace with your actual API key const data = { name: "BANGING MY HEAD!", // Customize your event name email: 'Yourname@email.com', // Replace with dynamic data timestamp: Math.floor(Date.now() / 1000).toString(), metadata: { page: window.location.href, // Optionally track the page URL referrer: document.referrer // Optionally track referrer } }; fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${apiKey}` }, body: JSON.stringify(data) }) .then(response => { if (!response.ok) { throw new Error('Network response was not ok'); } return response.json(); // Assuming the response is JSON }) .then(data => { console.log('Event tracked successfully:', data); }) .catch(error => { console.error('Error tracking event:', error); });