UNPKG

tramatm-analytics-mixpanel

Version:

Mixpanel plugin for 'analytics' module

1 lines 2.85 kB
var analyticsMixpanel=function(){"use strict";return function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{name:"mixpanel",config:e,initialize:function(e){var t=e.config,n=t.token,i=t.customScriptSrc;if(!n)throw new Error("No mixpanel token defined");void 0===window.mixpanel&&(!function(e,t){if(!t.__SV){var n,a,o=window;try{var r,p,c,l=o.location,s=l.hash;r=function(e,t){return(p=e.match(RegExp(t+"=([^&]*)")))?p[1]:null},s&&r(s,"state")&&("mpeditor"===(c=JSON.parse(decodeURIComponent(r(s,"state")))).action&&(o.sessionStorage.setItem("_mpcehash",s),history.replaceState(c.desiredHash||"",e.title,l.pathname+l.search)))}catch(e){}window.mixpanel=t,t._i=[],t.init=function(e,i,o){function r(e,t){var n=t.split(".");2==n.length&&(e=e[n[0]],t=n[1]),e[t]=function(){e.push([t].concat(Array.prototype.slice.call(arguments,0)))}}var p=t;for(void 0!==o?p=t[o]=[]:o="mixpanel",p.people=p.people||[],p.toString=function(e){var t="mixpanel";return"mixpanel"!==o&&(t+="."+o),e||(t+=" (stub)"),t},p.people.toString=function(){return p.toString(1)+".people (stub)"},n="disable time_event track track_pageview track_links track_forms track_with_groups add_group set_group remove_group register register_once alias unregister identify name_tag set_config reset opt_in_tracking opt_out_tracking has_opted_in_tracking has_opted_out_tracking clear_opt_in_out_tracking people.set people.set_once people.unset people.increment people.append people.union people.track_charge people.clear_charges people.delete_user people.remove".split(" "),a=0;a<n.length;a++)r(p,n[a]);var c="set set_once union unset remove delete".split(" ");p.get_group=function(){function e(e){t[e]=function(){call2_args=arguments,call2=[e].concat(Array.prototype.slice.call(call2_args,0)),p.push([n,call2])}}for(var t={},n=["get_group"].concat(Array.prototype.slice.call(arguments,0)),i=0;i<c.length;i++)e(c[i]);return t},t._i.push([e,i,o])},t.__SV=1.2,(o=e.createElement("script")).type="text/javascript",o.async=!0,o.src=i||("undefined"!=typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js"),(r=e.getElementsByTagName("script")[0]).parentNode.insertBefore(o,r)}}(document,window.mixpanel||[]),mixpanel.init(t.token,{batch_requests:!0}))},identify:function(e){var t=e.payload,n=t.userId,i=t.traits;"string"==typeof n&&mixpanel.identify(n),i&&mixpanel.people.set(i)},page:function(e){var t=e.payload;mixpanel.track(t.properties.pageName,{search:t.properties.search})},track:function(e){var t=e.payload;mixpanel.track(t.event,t.properties)},loaded:function(){return!!window.mixpanel},reset:function(){mixpanel.reset()},methods:{alias:function(e,t){mixpanel.alias(e,t)}}}}}();