- Tracking detailed user activity (which is the advantage of using Mixpanel in the first place) is cumbersome with GTM and will still require implementing code on your site itself, negating the main advantage of GTM (being able to make changes to tracking without code changes on your site itself).
- Debugging any issues that arise is more difficult if you’ve integrated using GTM.
If you do decide to implement Mixpanel using GTM, you can do so by:
- Creating a GTM Container: See Google’s documentation on setup and getting started for additional guidance.
- Create a Mixpanel project: While you’re logged into your Mixpanel account, click on the project dropdown in the top left corner of the page, fill in a name at the bottom of the list, and click Create Project.
- Initialize the Mixpanel library: While you can try to use GTM to load the Mixpanel library, we recommend placing the Mixpanel snippet on the page directly if possible to ensure it loads properly (i.e., before any of your track calls).
- Create Mixpanel tags: Select Custom HTML from the list of tag types to create a new Mixpanel tag. From there, insert mixpanel.track() calls to track the particular action that users perform with this tag.
- Define rules for when tags should send data: Next, select a rule that injects your tags on certain pages of your site (e.g., if you only want this tag to fire when the landing page loads, you’ll need to create a custom rule to target just the landing page).
If you want to track actions outside of pageviews, to get that level of detail with GTM, you’d have to implement a “data layer object” that allows you to pass variable information from the various parts of your site to the tags you inject with GTM. Read more about Data Layers.