You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added some public docs on custom initialization options for GTM implementation, both generally and for autocapture. Mikey and Chi both reviewed and blessed
Copy file name to clipboardExpand all lines: pages/docs/tracking-methods/integrations/google-tag-manager.mdx
+74Lines changed: 74 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,6 +33,80 @@ When *any* Mixpanel GTM tag fires, it automatically tries to initialize a new in
33
33
34
34
This way the user doesn't need to worry about initialization. They just need to make sure that the Initialization Options are configured consistently across the tags.
35
35
36
+
#### Custom Initialization Options
37
+
38
+
To add initialization options for capabilities like [session replay](https://docs.mixpanel.com/docs/tracking-methods/sdks/javascript#implementation--sampling) (`record_sessions_percent`)or [heatmaps](https://docs.mixpanel.com/docs/tracking-methods/sdks/javascript#heatmaps-beta) (`record_heatmap_data`) to Google Tag Manager:
39
+
40
+
1\. Add a new tag in GTM and choose the Mixpanel tag type
41
+
42
+
2\. For Project Token field, enter your Mixpanel project token
43
+
44
+
3\. For Tag Type select init from the dropdown
45
+
46
+
4\. For Initialization choose Set Options Manually
47
+
48
+
5\. In the Option key / Option value section, add the relevant key-value pair according to your needs (e.g.; `record_heatmap_data` as the key and set a boolean value of `true`)
49
+
50
+
6\. For the Triggering section, choose an early GTM lifecycle event like Initialization \- All Pages or Consent Initialization \- All Pages
51
+
52
+
#### GTM with custom Autocapture initialization options
53
+
54
+
To use [autocapture initialization options](https://docs.mixpanel.com/docs/tracking-methods/sdks/javascript#autocapture) like `capture_extra_attrs` with GTM, you'll need to create a custom JavaScript variable in GTM and then use that variable for your autocapture configuration. Here's how to do it:
55
+
56
+
##### **1\. Create a Custom JavaScript Variable in GTM**
57
+
58
+
First, create a Custom JavaScript variable that returns the autocapture configuration object:
59
+
60
+
1\. In GTM, go to Variables \> User-Defined Variables \> New
61
+
62
+
2\. Choose "Custom JavaScript" as the variable type
63
+
64
+
3\. Add code that returns the autocapture configuration object, including the `capture_extra_attrs` option
65
+
66
+
For example, the Custom JavaScript variable might look like this:
##### **2\. Use the Variable in Your Mixpanel Tag**
91
+
92
+
Once the custom variable is created:
93
+
94
+
1\. Edit the Mixpanel initialization tag in GTM
95
+
96
+
2\. For the Autocapture option, instead of selecting "Enabled" or "Disabled" from the dropdown, select the custom JavaScript variable
97
+
98
+
##### **3\. Verify Your Implementation**
99
+
100
+
After setting up the tag with the custom variable:
101
+
102
+
1\. Use GTM's preview mode to verify that the tag is firing correctly
103
+
104
+
2\. Check in the browser's developer console that the Mixpanel configuration includes the custom autocapture settings
105
+
106
+
3\. Verify in Mixpanel that the extra attributes are being captured with your events
107
+
108
+
This approach allows for customized autocapture options beyond the simple enabled/disabled toggle that's available in the standard GTM template interface.
109
+
36
110
### Sending Mixpanel Commands
37
111
38
112
After adding the **Project Token** to its respective field, you need to choose what **type** of tag to use. Each type corresponds with some command you can use with the Mixpanel JS API.
0 commit comments