Skip to content

Commit 8a5dcf5

Browse files
Update google-tag-manager.mdx (#1849)
Added some public docs on custom initialization options for GTM implementation, both generally and for autocapture. Mikey and Chi both reviewed and blessed
1 parent f0a6b38 commit 8a5dcf5

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

pages/docs/tracking-methods/integrations/google-tag-manager.mdx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,80 @@ When *any* Mixpanel GTM tag fires, it automatically tries to initialize a new in
3333

3434
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.
3535

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:
67+
68+
```
69+
function() {
70+
71+
return {
72+
73+
pageview: "full-url",
74+
75+
click: true,
76+
77+
input: true,
78+
79+
scroll: true,
80+
81+
submit: true,
82+
83+
capture_extra_attrs: \['data-cta-name', 'data-cta-position'\]
84+
85+
};
86+
87+
}
88+
```
89+
90+
##### **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+
36110
### Sending Mixpanel Commands
37111

38112
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

Comments
 (0)