UNPKG

@alibaba-aero/vue-webengage

Version:
3 lines (2 loc) 2.5 kB
"use strict";var loggerModule={init:function(e){var n=e.debug;return{log:function(){var e;n&&(e=console).log.apply(e,arguments)},warn:function(){var e;n&&(e=console).warn.apply(e,arguments)},table:function(){var e;n&&(e=console).table.apply(e,arguments)},dir:function(){var e;n&&(e=console).dir.apply(e,arguments)},error:function(){var e;n&&(e=console).error.apply(e,arguments)}}}},loader={load:function(e){if(!window.webengage){var n=document.createElement("scipt");n.type="text/javascript",n.id="_webengage_script_tag",document.getElementsByTagName("head")[0].appendChild(n),function(e,n,t,o,a){function i(e,n){e[n[n.length-1]]=function(){g.__queue.push([n.join("."),arguments])}}var r,l,g=e[t],c=" ",u="init options track screen onReady".split(c),s="feedback survey notification".split(c),d="options render clear abort".split(c),p="Open Close Submit Complete View Click".split(c),f="identify login logout setAttribute".split(c);if(!g||!g.__v){for(e[t]=g={__queue:[],__v:"6.0",user:{}},r=0;r<u.length;r++)i(g,[u[r]]);for(r=0;r<s.length;r++){for(g[s[r]]={},l=0;l<d.length;l++)i(g[s[r]],[s[r],d[l]]);for(l=0;l<p.length;l++)i(g[s[r]],[s[r],"on"+p[l]])}for(r=0;r<f.length;r++)i(g.user,["user",f[r]]);setTimeout(function(){var e=n.createElement("script"),t=n.getElementById("_webengage_script_tag");e.type="text/javascript",e.async=!0,e.src=("https:"==n.location.protocol?"https://ssl.widgets.webengage.com":"http://cdn.widgets.webengage.com")+"/js/webengage-min-v-6.0.js",t.parentNode.insertBefore(e,t)})}}(window,document,"webengage"),window.webengage.init(e)}return window.webengage}},defaultOptions={namespace:"webengage"},goodToGo=function(e){return e.$options.webengage},evaluate=function(e,n,t){return"function"==typeof e?e.call(t,n):e},vueWebengage={install:function(e,n){if(!(null==n?void 0:n.key))throw new Error("You have to define webengage key. got undefined");var t=loader.load(n.key);e.mixin({beforeCreate:function(){if(goodToGo(this)){var e=this;t.onReady(function(){t.debug(!!(null==n?void 0:n.debug))});var o=loggerModule.init({debug:n.debug||e.$options.webengage.debug}),a=(null==n?void 0:n.namespace)||defaultOptions.namespace;this["$".concat(a)]={service:t,track:function(a,i){try{var r=evaluate(e.$options.webengage,null==n?void 0:n.schemas,e),l=evaluate(r[a],i,e);o.log("%cWebengage event ->","background:#eaeaea;color:green;",a),o.table(l),t.track(a,l)}catch(e){o.dir(e),o.error("Error in ".concat(a),e)}}}}}})}};module.exports=vueWebengage; //# sourceMappingURL=vue-webengage.js.map