3 Best Mixpanel WordPress Integration Methods

Mixpanel is a powerful, on-site web analytics application focused on complex event tracking and A/B testing for deep user behavior analysis. Externally hosted on Mixpanel.com, the analytics toolkit can produce in-depth dashboards and experiments based on what users do in webpages, contact forms, and other interactive website elements. This will help you improve customer retention and digital product engagement for up-selling opportunities.

Many digital product marketing experts debate whether it’s a better option or worthy alternative to Google Analytics. Mixpanel is a strong choice if user segmentation and activity, rather than just where users are coming from, is the core need from your analytics application. Others argue that organizations should use both for their differing strengths for a full-fledged product analytics stack.

What’s less debatable is that business owners using a content management system (CMS) such as WordPress and PrestaShop want a straightforward method for integrating Mixpanel without sacrificing the ongoing task that is cybersecurity.

Below we’ll cover how to:

Improve the performance and security of your WordPress website with our Managed WordPress VPS Hosting plans.

check markWeb Application Firewalls check markFree SSL Certificates check markAdvanced Server Caching

Managed WordPress Plans

Integrate Mixpanel in WordPress with a Plugin

There are a few WordPress plugins for Mixpanel integration. We’ll discuss the pros and cons of the two most popular ones.

Premium Mixpanel Plugin for WooCommerce

There’s a paid Mixpanel WooCommerce plugin by Skyverge for those willing to pay for complex analytics management within your WordPress dashboard. Once you add your Mixpanel token ID in the plugin settings, your WooCommerce Mixpanel integration is squared away.

However, this option won’t satisfy WordPress users who are:

  • Using a different eCommerce plugin other than WooCommerce
  • Not wanting to pay for a premium WordPress plugin
  • Content with only viewing analytics in an external dashboard (Mixpanel.com in this case)

MixPanel Plugin for WordPress

Some users may resort to using the outdated MixPanel WordPress plugin by Jitta Raghavender Rao, if they don’t give up on using Mixpanel entirely. It’s really easy to use: 

MixPanel plugin settings
  1. Install the WordPress plugin.
  2. In the WordPress dashboard, go to Settings > Mixpanel Options.
  3. Type your Mixpanel token ID, “false”, and “false” again (unless you have subdomains under the site).
  4. Click Save Changes.

But again, the issue is that the plugin is outdated. It hasn’t been updated in over six years. This is a major security risk as many cyber attacks result from exploited known vulnerabilities in outdated, abandoned software. It doesn’t matter how much work you may have done to harden your VPS or unmanaged server, how strict your web application firewall (WAF) is, or what antivirus (AV) software you have running regularly with a fancy cron job. You would become an easier target for cyber criminals.

That brings us to the recommended method of integrating Mixpanel in WordPress websites.

Integrate Mixpanel in WordPress with the JavaScript API

Mixpanel warns that using the JavaScript application programming interface (API) is the best way to get the most out of Mixpanel as other integration methods restrict your capabilities. This is because of the sheer amount of customization possible with Mixpanel JavaScript calls, how you code your website, and how you want to track what and where.

Still, that shouldn’t be too surprising. Google Analytics plugins don’t allow you to do everything in WordPress as you can in the external dashboard. There is, for example, a Matomo WordPress plugin that houses most features from the standalone web application. But that’s a fully developed analytics suite within the plugin, not an integration to an external web app.

Regardless, what if you don’t care for an analytics suite in your dashboard? What if you’re simply testing Mixpanel against Google Analytics or other options to determine what’s best for your needs? Only being able to manipulate log analysis in an external website might be enough for you to get a decent feel on the user experience (UX) of Mixpanel’s capabilities.

Hacking MixPanel for Mixpanel

If you read the MixPanel plugin description, you’ll see the following statement:

You no longer need to add the mixpanel.track() javascript snippet in your theme files.

This made me wonder: what is that full mixpanel.track code and where exactly does it go? So I begrudgingly installed and configured the outdated MixPanel plugin. Then I searched for the Mixpanel script with the Firefox HTML inspector. After finding the plugin’s default Javascript code in the <body> section, I wondered what’s a better way to insert the simple tracking code into WordPress. This led me to use the Insert Headers and Footers plugin which eases the ability to add schema markup for search engine optimization (SEO).

It worked!

Now, is it a little dank? Yes.

Are there better ways to accomplish this? Most likely. This method still requires installing another plugin. You could edit your functions.php file instead. Issues might arise which affect your theme or other plugins, though.

Is it worth a shot? Yeah, it’s better than hoping your website isn’t infiltrated because of a years-old plugin.

Will it break the website? It should not. But if you’re using Content-Security-Policy (CSP), you may need to add https://*.mixpanel.com/* to your CSP header. Otherwise, the script won’t load in browsers to track user input.

Using the Insert Headers and Footers Plugin

  1. Log into your WordPress dashboard.
  2. Install the Insert Headers and Footers plugin.
  3. Mixpanel HTML code snippet
    Create an account at Mixpanel.com.
  4. On the Set up Mixpanel page, under Install Library (SDK), copy the HTML snippet.
  5. In your WordPress dashboard, select Settings, then Insert Headers and Footers.
  6. Paste the Mixpanel HTML snippet into the Scripts in Header section.
  7. Mixpanel scripts in Insert Headers and Footers plugin
    The code below is from the MixPanel plugin. As stated earlier, this option is easier than editing your WordPress files. But this tracking code will only gather page views. You’ll need to research official Mixpanel documentation or contact a developer to produce an in-depth tracking solution. Add the following JavaScript code in the plugin Scripts in Body section:
    <script>mixpanel.track("Viewed Page", {'Page Name': document.title, 'Page URL': window.location.pathname});</script>
  8. At the bottom, select Save.
  9. View a couple of your WordPress site pages in a private browsing session.
  10. On the bottom of your Mixpanel setup page, beside Check for Incoming Data, select Check.
  11. You should see “We successfully received your data!” Select Start Using Mixpanel.

View Basic Analytics in Mixpanel

At this point, you can create a Mixpanel dashboard to compile the information you want to focus on. To quickly see results, though, use the Insights tool.

  1. At the top, select Analysis > Insights.
  2. Select Your Top Events, then Viewed Page.
  3. Under Breakdowns, select + Add.
  4. Select Page Name. From here, you can add additional filters and chart changes to fit your needs.
Mixpanel Insights Report

Still have questions about integrating Mixpanel with WordPress? Know a better way? Let us know in the comments below.

InMotion Hosting Contributor
InMotion Hosting Contributor Content Writer

InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!

More Articles by InMotion Hosting

Was this article helpful? Join the conversation!

Questions about our MailChannels Deployment? We have answers and are here to help!Learn More
+