Rather than setting up IDs and setting up a separate tracking event for each link (my code changes often), I was wondering if there was a way I could set Mixpanel up to track all links (and buttons even) and get the value of the link eg "/readmore"
so that I don't have to code for each possibility.
I looked at the Mixpanel Javascript API reference and read about mixpanel.track_links which seems to be in the right direction for what I am looking for, but i have to specify a "name"
upfront which would register all events with the same name?
Here's some example code from the mixpanel api reference:
// with properties function
mixpanel.track_links
("#footer", "Footer link", function(ele) { return { type: $(ele).attr('type')}});
I'd like to replace "#footer"
with say "a"
i.e all links, and then for the value of the link to be returned.
Is this even possible?
mixpanel. track_links("#MyLink","Clicked Link"); The first argument is a css-style selector for the link you want to track, the second argument is the name of the event. You can even add a third argument for the properties, and this is all documented in the full track_links documentation.
You can track a “Sign-up Page View” event and in the event properties you can describe which page they are looking at. mixpanel. track(“Sign-up Page View”, { page: “email screen” });
An initial referrer is equal to $direct when a user first lands on a site without being referred by another website. The user may have typed the website address directly, clicked a bookmark, clicked a link from an email, or might have security settings in their browser that prevent referrer data from being passed.
identify. Identify a user with a unique ID to track user activity across devices, tie a user to their events, and create a user profile. If you never call this method, unique visitors are tracked using a UUID generated the first time they visit the site.
From what I've seen, the mixpanel selector engine is quite limited and it appears that multiple selector syntax is not supported. However, if you give all your button
and anchor
elements a class, you will be able to target them with one call to track_links
(with the added advantage that you can easily exclude elements you don't want to track):
mixpanel.track_links(".mixpanel-tracked", "Link clicked", function(ele) {
return { type: $(ele).attr('type') }
});
If you can't use a class for whatever reason, you could target multiple elements by naming your function and passing a reference to it to separate calls to the track_links
function:
var getLinkData = function(ele) {
return { type: $(ele).attr('type') }
}
mixpanel.track_links('a', 'Link clicked', getLinkData);
mixpanel.track_links('input', 'Link clicked', getLinkData);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With