Skip to content

Commit ec33022

Browse files
authored
Merge pull request #181 from laurence-hudson-mindfoundry/master
Improve mixpanel page events
2 parents adc4fbe + a444328 commit ec33022

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

packages/analytics-plugin-mixpanel/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ const analytics = Analytics({
111111
| Option | description |
112112
|:---------------------------|:-----------|
113113
| `token` <br/>**required** - string| The mixpanel token associated to a mixpanel project |
114+
| `pageEvent` <br/>_optional_ - string| Event name to use for page() events (default to page path) |
114115
| `customScriptSrc` <br/>_optional_ - string| Load mixpanel script from custom source |
115116

116117

packages/analytics-plugin-mixpanel/src/browser.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* @link https://getanalytics.io/plugins/mixpanel/
44
* @param {object} pluginConfig - Plugin settings
55
* @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)
68
* @param {string} [pluginConfig.customScriptSrc] - Load mixpanel script from custom source
79
* @return {object} Analytics plugin
810
* @example
@@ -17,7 +19,7 @@ function mixpanelPlugin(pluginConfig = {}) {
1719
config: pluginConfig,
1820
/* https://developer.mixpanel.com/docs/javascript-full-api-reference#mixpanelinit */
1921
initialize: ({ config }) => {
20-
const { token, customScriptSrc } = config;
22+
const { token, customScriptSrc, options = {} } = config;
2123
if (!token) {
2224
throw new Error("No mixpanel token defined");
2325
}
@@ -118,7 +120,7 @@ function mixpanelPlugin(pluginConfig = {}) {
118120
}
119121
})(document, window.mixpanel || []);
120122

121-
mixpanel.init(config.token, { batch_requests: true });
123+
mixpanel.init(config.token, { batch_requests: true, ...options });
122124
},
123125
/**
124126
* Identify a visitor in mixpanel
@@ -141,9 +143,7 @@ function mixpanelPlugin(pluginConfig = {}) {
141143
* the path as tracked event and search parameters as properties
142144
*/
143145
page: ({ payload }) => {
144-
mixpanel.track(payload.properties.path, {
145-
search: payload.properties.search,
146-
});
146+
mixpanel.track(pluginConfig.pageEvent || payload.properties.path, payload.properties);
147147
},
148148
/* https://developer.mixpanel.com/docs/javascript-full-api-reference#mixpaneltrack */
149149
track: ({ payload }) => {

0 commit comments

Comments
 (0)