add opt out for mixpanel tracking
This commit is contained in:
@@ -43,4 +43,4 @@ export { default as Shortcuts } from '../src/javascripts/shortcuts.js';
|
||||
export { default as Upload } from '../src/javascripts/uploads.js';
|
||||
export { default as Utility } from '../src/javascripts/utility.js';
|
||||
export { default as Ugoira } from '../src/javascripts/ugoira.js';
|
||||
|
||||
export { mixpanelInit, mixpanelEvent } from '../src/javascripts/mixpanel.js';
|
||||
|
||||
27
app/javascript/src/javascripts/mixpanel.js
Normal file
27
app/javascript/src/javascripts/mixpanel.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const mixpanelInit = (user_id, session_id, opt_out, user_data) => {
|
||||
if (typeof window.mixpanel !== "object") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (user_id) {
|
||||
window.mixpanel.identify(user_id);
|
||||
|
||||
if (opt_out) {
|
||||
window.mixpanel.opt_out_tracking();
|
||||
} else {
|
||||
window.mixpanel.people.set(user_data);
|
||||
}
|
||||
} else if (session_id) {
|
||||
window.mixpanel.identify("anon:" + session_id);
|
||||
}
|
||||
}
|
||||
|
||||
const mixpanelEvent = (title, props) => {
|
||||
if (typeof window.mixpanel !== "object") {
|
||||
return;
|
||||
}
|
||||
|
||||
window.mixpanel.track(title, props);
|
||||
}
|
||||
|
||||
export { mixpanelInit, mixpanelEvent };
|
||||
Reference in New Issue
Block a user