Sivagurunathan N. Try this <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Mixpanel Link Tracking Example</title> <script type="text/javascript"> (function(f,b){if(!b.__SV){var e,g,i,h;window.mixpanel=b;b._i=[];b.init=function(a,j,d){function k(c,l){var m=l.split(".");2==m.length&&(c=c[m[0]],l=m[1]);c[l]=function(){c.push([l].concat(Array.prototype.slice.call(arguments,0)))}}var n=f.createElement("script");n.type="text/javascript";n.async=!0;n.src="https://cdn.mixpanel.com/track.js";e=f.getElementsByTagName("script")[0];e.parentNode.insertBefore(n,e);for(g="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify reset opt_in_tracking opt_out_tracking has_opted_in_tracking has_opted_out_tracking clear_opt_in_out_tracking start_batch_senders people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user people.remove people.unset".split(" "),i=0;i<g.length;i++)h=g[i],k(b,h);b._i.push([a,j,d])};b.__SV=1.2;}})(document,window.mixpanel||[]); // --- Mixpanel Initialization and Tracking --- mixpanel.init('YOUR_MIXPANEL_PROJECT_TOKEN', { // <-- REPLACE with your actual Mixpanel token debug: true, // Set to false in production to stop console logs track_pageview: 'fullUrl', // Automatically track page views with full URL autocapture: { pageview: false, // track_pageview handles this click: false, // **IMPORTANT: Disable default click autocapture** to avoid duplicates with track_links input: true, scroll: true, submit: true }, // Add other global configuration options here if needed }); // Register global properties that should be sent with ALL events // Example: // mixpanel.register({ // 'User Role': 'Guest', // 'Source Campaign': 'Summer Sale 2025' // }); // --- Track specific link clicks using mixpanel.track_links() --- // This function efficiently tracks clicks on all <a> tags. // It prevents default navigation, sends the event, and then navigates. mixpanel.track_links('a', 'Anchor Clicked', function(element) { // This function defines the properties for the 'Anchor Clicked' event. // 'element' is the actual DOM element (the <a> tag) that was clicked. const href = element.href; // Filter out hash links or javascript: links if you don't want to track them if (!href || href.startsWith('#') || href.startsWith('javascript:')) { return false; // Returning false tells track_links NOT to track this specific link } return { 'Anchor Text': element.textContent.trim(), // Captures the visible text of the link 'Href': href, // Captures the full URL 'Element ID': element.id || 'N/A', // Captures the ID, if present 'Element Class': element.className || 'N/A' // Captures the class, if present }; }); </script> </head> <body> <h1>Website Content</h1> <p>Click these links to see Mixpanel tracking in action:</p> <a href="https://www.example.com/products" id="products-link" class="nav-item">View Products</a><br> <a href="/about-us" class="footer-link">About Our Company</a><br> <a href="https://mixpanel.com/docs/" target="_blank">Mixpanel Documentation</a><br> <a href="#top-of-page">Jump to Top</a> (This link will **not** be tracked due to the filter)<br> <a href="javascript:void(0);">Do Something Else</a> (This link will **not** be tracked)<br> <p>Other content on your page...</p> </body> </html>
and you can use this query in which u can group users who do not have challenge id as unkown group function main() { return Events({ from_date: '2025-01-01', to_date: '2025-12-31', event_selectors: [{ event: 'JOIN_CHALLENGE' }] }) .groupBy([function(e) { return e.properties.challenge_id || 'unknown'; }, "distinct_id"], function(events, key) { return true; }) .groupBy(["key[0]"], function(state) { state = state || { users_joined: 0 }; state.users_joined += 1; return state; }) .map(function(key, value) { return { challenge_id: key[0], users_joined: value.users_joined }; }); }
this will give u only users per challenge, this will skip which do not have challenge id associated with them function main() { return Events({ from_date: '2025-01-01', to_date: '2025-12-31', event_selectors: [{ event: 'JOIN_CHALLENGE' }] }) .filter(function(event) { return !!event.properties.challenge_id; // skip events without challenge_id }) .groupBy(["properties.challenge_id", "distinct_id"], function(events, key) { return true; }) .groupBy(["key[0]"], function(state) { state = state || { users_joined: 0 }; state.users_joined += 1; return state; }) .map(function(key, value) { return { challenge_id: key[0], users_joined: value.users_joined }; }); }
Ansh A. Try this, function main() { return Events({ from_date: '2025-01-01', to_date : '2025-12-31', event_selectors: [{ event: 'JOIN_CHALLENGE' }] }) .groupBy(["properties.challenge_id", "distinct_id"], function(events, key) { return { joined: true }; // each user per challenge }) .groupBy(["key[0]"], function(state, row) { state = state || { users_joined: 0 }; state.users_joined += 1; return state; }) .map(function(key, value) { return { challenge_id: key[0], users_joined: value.users_joined }; }); }
Ansh A. function main() { return Events({ from_date: '2025-01-01', to_date : '2025-12-31', event_selectors: [{ event: 'JOIN_CHALLENGE' }] }) .groupBy(["properties.challenge_id"], function(events, key) { var userSet = {}; events.forEach(function(event) { if (event.distinct_id) { userSet[event.distinct_id] = true; } }); return { users_joined: Object.keys(userSet).length }; }) .map(function(key, value) { return { challenge_id: key[0], users_joined: (value && value.users_joined) || 0 }; }); }
Ansh A. function main() { return Events({ from_date: '2025-01-01', to_date : '2025-12-31', event_selectors: [{ event: 'JOIN_CHALLENGE' }] }) .groupBy(["properties.challenge_id"], function(events, key) { var userSet = {}; events.forEach(function(event) { userSet[event.distinct_id] = true; }); return { users_joined: Object.keys(userSet).length }; }) .map(function(key, value) { return { challenge_id: key[0], users_joined: value.users_joined }; }); }
Ansh A. try running this to see if any events are returned function main() { return Events({ from_date: '2025-01-01', to_date : '2025-12-31', event_selectors: [{ event: 'JOIN_CHALLENGE' }] }) .map(function(event) { return { challenge_id: event.properties.challenge_id || 'missing', distinct_id: event.distinct_id }; }); }