JavaScript newbie - Am I doing this right? Setting up MixPanel

On my wordpress page, I’ve got this right at the top:

<script type="text/javascript">
    mixpanel.track(
    "AESML page"
);
    mixpanel.track_links("#aesml-i", "Click AESML link", {
        "referrer": document.referrer
    });
</script>

And somewhere below on the page, I’ve got:

<div id="aesml-i" align="center"><a href="http://website.com/event-registration/?ee=5" onclick="mixpanel.track_links("#aesml-i", "Click AESML Row 1 register link");return false;">Register Now</a> | <a href="http://website.com/contact-us/">Contact Us For Assistance</a></div>

As you can tell, I’m attempting to track link clicks by calling the function.

What am I doing wrong? Tks much!

Hi,

I have no experience of using this, but had a quick look at the docs and will see if I can help.

As you can read, mixpanel.track_links has two required parameters:

css_selector:string - A valid CSS selector that matches the link(s) you want to track, preferably an ID.
event_name:string - The name of the event to send when a link is clicked. This can be anything you want, like “clicked header link” or “footer link click”.

Regarding the first parameter, might it be the case that you have to add the id to the anchor tag itself, as opposed to its parent div?

You have:

<div id="aesml-i" align="center">
  <a href="http://website.com/event-registration/?ee=5" onclick="mixpanel.track_links("#aesml-i", "Click AESML Row 1 register link");return false;">Register Now</a> | 
  <a href="http://website.com/contact-us/">Contact Us For Assistance</a>
</div>

Might this be better:

<div align="center">
  <a href="http://website.com/event-registration/?ee=5" id="aesml-i" onclick="mixpanel.track_links("#aesml-i", "Click AESML Row 1 register link");return false;">Register Now</a> | 
  <a href="http://website.com/contact-us/">Contact Us For Assistance</a>
</div>

Admittedly, this is a bit of a shot in the dark.