3
3
* @link https://getanalytics.io/plugins/mixpanel/
4
4
* @param {object } pluginConfig - Plugin settings
5
5
* @param {string } pluginConfig.token - The mixpanel token associated to a mixpanel project
6
+ * @param {object } [pluginConfig.options] - The mixpanel init options https://github.com/mixpanel/mixpanel-js/blob/8b2e1f7b/src/mixpanel-core.js#L87-L110
7
+ * @param {string } [pluginConfig.pageEvent] - Event name to use for page() events (default to page path)
6
8
* @param {string } [pluginConfig.customScriptSrc] - Load mixpanel script from custom source
7
9
* @return {object } Analytics plugin
8
10
* @example
@@ -17,7 +19,7 @@ function mixpanelPlugin(pluginConfig = {}) {
17
19
config : pluginConfig ,
18
20
/* https://developer.mixpanel.com/docs/javascript-full-api-reference#mixpanelinit */
19
21
initialize : ( { config } ) => {
20
- const { token, customScriptSrc } = config ;
22
+ const { token, customScriptSrc, options = { } } = config ;
21
23
if ( ! token ) {
22
24
throw new Error ( "No mixpanel token defined" ) ;
23
25
}
@@ -118,7 +120,7 @@ function mixpanelPlugin(pluginConfig = {}) {
118
120
}
119
121
} ) ( document , window . mixpanel || [ ] ) ;
120
122
121
- mixpanel . init ( config . token , { batch_requests : true } ) ;
123
+ mixpanel . init ( config . token , { batch_requests : true , ... options } ) ;
122
124
} ,
123
125
/**
124
126
* Identify a visitor in mixpanel
@@ -141,9 +143,7 @@ function mixpanelPlugin(pluginConfig = {}) {
141
143
* the path as tracked event and search parameters as properties
142
144
*/
143
145
page : ( { payload } ) => {
144
- mixpanel . track ( payload . properties . path , {
145
- search : payload . properties . search ,
146
- } ) ;
146
+ mixpanel . track ( pluginConfig . pageEvent || payload . properties . path , payload . properties ) ;
147
147
} ,
148
148
/* https://developer.mixpanel.com/docs/javascript-full-api-reference#mixpaneltrack */
149
149
track : ( { payload } ) => {
0 commit comments