Mixpanel Community Icon

Need Help with Auto Element Click Event in MP Tool

·
·

👋 Hello, team! Im started using MP for my organisation and Im new to the tool and still learning. I got stuck on Auto Element Click event where I couldn't see $element_text property and it values for each click event. I enabled autocapture true for click events. Still I couldn't see, can anyone please help me on this? Below is my code structure mixpanel.init('', { autocapture: { pageview: false, click: true, input: true, scroll: true, submit: true }, }); mixpanel.register({ my code here }); // Tried this to add the $element_text since values not showing on default $('a').on('click', function (e) { const anchorText = $(this).text().trim(); const href = $(this).attr('href'); // Skip tracking if it's a hash or JS-only link if (!href || href.startsWith('#') || href.startsWith('javascript:')) { return; } // Stop default behavior to allow event to send e.preventDefault(); // Track the anchor click manually mixpanel.track('Anchor Clicked', { 'Anchor Text': anchorText, 'Href': href }); // Delay navigation just enough for Mixpanel to send the event setTimeout(() => { window.location.href = href; }, 200); // You can increase to 300ms if needed });

  • Avatar of Julianne Bozzini
    Julianne Bozzini
    APP
    ·
    ·

    Hi Sivagurunathan- Julianne from Mixpanel Support here. The default initialization for Autocapture doesn't include capture textContent. However, you can set capture_text_content: true as an init option. When set to true, Mixpanel will capture the textContent of any element. Mind giving that a try to see if that allows you to capture the textContent?

  • Avatar of Sivagurunathan N.
    Sivagurunathan N.
    ·
    ·

    Hi Julianne - I have tried this already and still its not working. Wondering any other way to achieve this?

  • Avatar of Vipul S.
    Vipul S.
    ·
    ·

    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>

  • Avatar of Julianne Bozzini
    Julianne Bozzini
    APP
    ·
    ·

    Sorry to hear the capture_text_content isn't working- can you submit a ticket via our webform so we can troubleshoot your specific project instance?

\n\n\n\n

Website Content

\n

Click these links to see Mixpanel tracking in action:

\n\n View Products
\n About Our Company
\n Mixpanel Documentation
\n Jump to Top (This link will **not** be tracked due to the filter)
\n Do Something Else (This link will **not** be tracked)
\n\n

Other content on your page...

\n\n\n","author":{"@type":"Person","name":"Vipul S.","url":"/user/9c9142ac-0880-411f-a365-1b3508021f1e"},"datePublished":"2025-07-01T07:30:49.829664+00:00","dateModified":"2025-07-01T07:30:49.829664+00:00","interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0}},{"@type":"Comment","text":"Sorry to hear the capture_text_content isn't working- can you submit a ticket via our webform (https://mixpanel.com/get-support)so we can troubleshoot your specific project instance?\n","author":{"@type":"Person","name":"Thena","url":"/user/b2d56d02-bff9-4dea-9d6d-7175e251b9e9"},"datePublished":"2025-07-01T18:15:50.936204+00:00","dateModified":"2025-07-01T18:15:50.936204+00:00","interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0}}]}