@edx/frontend-analytics
Advanced tools
Comparing version 1.0.4 to 2.0.0
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["frontend-analytics"]=t():e["frontend-analytics"]=t()}("undefined"!=typeof self?self:this,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.sendTrackingLogEvent=t.sendTrackEvent=t.sendPageEvent=t.initializeSegment=t.identifyAuthenticatedUser=t.identifyAnonymousUser=t.configureAnalytics=void 0;var r=n(1),o=n(6);t.configureAnalytics=r.configureAnalytics,t.identifyAnonymousUser=r.identifyAnonymousUser,t.identifyAuthenticatedUser=r.identifyAuthenticatedUser,t.initializeSegment=o.initializeSegment,t.sendPageEvent=r.sendPageEvent,t.sendTrackEvent=r.sendTrackEvent,t.sendTrackingLogEvent=r.sendTrackingLogEvent},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.sendTrackingLogEvent=t.sendTrackEvent=t.sendPageEvent=t.identifyAuthenticatedUser=t.identifyAnonymousUser=t.configureAnalytics=void 0;var r=function(e){return e&&e.__esModule?e:{default:e}}(n(2)),o=n(3),i={},u=!1;function f(){if(!i.authApiClient)throw Error("You must configure the authApiClient.");return i.authApiClient}function c(){if(!i.loggingService)throw Error("You must configure the loggingService.");return i.loggingService}function a(){var e=c();u||e.logError("Identify must be called before other tracking events.")}t.configureAnalytics=function(e){u=!1,i={loggingService:e.loggingService,authApiClient:e.authApiClient,analyticsApiBaseUrl:e.analyticsApiBaseUrl}},t.identifyAnonymousUser=function(e){window.analytics.identify(e),u=!0},t.identifyAuthenticatedUser=function(e){var t=f().getAuthenticationState(),n=c();if(t.authentication&&t.authentication.userId)window.analytics.identify(t.authentication.userId,e),u=!0;else{var r="authState: "+JSON.stringify(t)+" cookies: "+document.cookie;n.logError("Failed to sendAuthenticatedIdentify. "+r)}},t.sendPageEvent=function(e,t,n){a(),window.analytics.page(e,t,n)},t.sendTrackEvent=function(e,t){a(),window.analytics.track(e,t)},t.sendTrackingLogEvent=function(e,t){var n=(0,o.snakeCaseObject)(t,{deep:!0}),u={event_type:e,event:JSON.stringify(n),page:window.location.href},a=c();return f().post(i.analyticsApiBaseUrl+"/event",(0,r.default)(u),{headers:{"Content-Type":"application/x-www-form-urlencoded"}}).catch(function(e){a.logAPIErrorResponse(e)})}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};t.default=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=Boolean(t.sorted),o=Boolean(t.skipIndex),i=Boolean(t.ignorenull),u=function(e){return String(e).replace(/(?:[\0-\x1F"-&\+-\}\x7F-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])/g,encodeURIComponent).replace(/ /g,"+").replace(/[!'()~\*]/g,function(e){return"%"+e.charCodeAt().toString(16).slice(-2).toUpperCase()})},f=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Object.keys(e);return n?t.sort():t},c=function(e){return e.filter(function(e){return e}).join("&")},a=function(e,t){return t.length?c(t.map(function(t,n){return l(o?e+"[]":e+"["+n+"]",t)})):u(e+"[]")},l=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0===t?"undefined":r(t),o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;return t===o?o=i?o:u(e)+"="+o:/string|number|boolean/.test(n)?o=u(e)+"="+u(t):Array.isArray(t)?o=a(e,t):"object"===n&&(o=function(e,t){return c(f(t).map(function(n){return l(e+"["+n+"]",t[n])}))}(e,t)),o};return e&&c(f(e).map(function(t){return l(t,e[t])}))}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.snakeCaseObject=void 0;var r=function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var n=[],r=!0,o=!1,i=void 0;try{for(var u,f=e[Symbol.iterator]();!(r=(u=f.next()).done)&&(n.push(u.value),!t||n.length!==t);r=!0);}catch(e){o=!0,i=e}finally{try{!r&&f.return&&f.return()}finally{if(o)throw i}}return n}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")},o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=function(e){return e&&e.__esModule?e:{default:e}}(n(4));t.snakeCaseObject=function(e){return function e(t,n){if(null==t||"object"!==(void 0===t?"undefined":o(t))&&!Array.isArray(t))return t;if(Array.isArray(t))return t.map(function(t){return e(t,n)});var i={};return Object.entries(t).forEach(function(t){var o=r(t,2),u=o[0],f=o[1];i[n(u)]=e(f,n)}),i}(e,i.default)}},function(e,t,n){(function(t){var n=1/0,r="[object Symbol]",o=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,i=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,u="\\xac\\xb1\\xd7\\xf7\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\u2000-\\u206f \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",f="["+u+"]",c="\\d+",a="[a-z\\xdf-\\xf6\\xf8-\\xff]",l="[^\\ud800-\\udfff"+u+c+"\\u2700-\\u27bfa-z\\xdf-\\xf6\\xf8-\\xffA-Z\\xc0-\\xd6\\xd8-\\xde]",s="(?:\\ud83c[\\udde6-\\uddff]){2}",d="[\\ud800-\\udbff][\\udc00-\\udfff]",y="[A-Z\\xc0-\\xd6\\xd8-\\xde]",p="(?:"+a+"|"+l+")",g="(?:"+y+"|"+l+")",v="(?:[\\u0300-\\u036f\\ufe20-\\ufe23\\u20d0-\\u20f0]|\\ud83c[\\udffb-\\udfff])?",b="[\\ufe0e\\ufe0f]?"+v+"(?:\\u200d(?:"+["[^\\ud800-\\udfff]",s,d].join("|")+")[\\ufe0e\\ufe0f]?"+v+")*",m="(?:"+["[\\u2700-\\u27bf]",s,d].join("|")+")"+b,x=RegExp("['’]","g"),h=RegExp("[\\u0300-\\u036f\\ufe20-\\ufe23\\u20d0-\\u20f0]","g"),A=RegExp([y+"?"+a+"+(?:['’](?:d|ll|m|re|s|t|ve))?(?="+[f,y,"$"].join("|")+")",g+"+(?:['’](?:D|LL|M|RE|S|T|VE))?(?="+[f,y+p,"$"].join("|")+")",y+"?"+p+"+(?:['’](?:d|ll|m|re|s|t|ve))?",y+"+(?:['’](?:D|LL|M|RE|S|T|VE))?",c,m].join("|"),"g"),S=/[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,j="object"==typeof t&&t&&t.Object===Object&&t,E="object"==typeof self&&self&&self.Object===Object&&self,O=j||E||Function("return this")(),w=function(e){return function(t){return null==e?void 0:e[t]}}({"À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","Ç":"C","ç":"c","Ð":"D","ð":"d","È":"E","É":"E","Ê":"E","Ë":"E","è":"e","é":"e","ê":"e","ë":"e","Ì":"I","Í":"I","Î":"I","Ï":"I","ì":"i","í":"i","î":"i","ï":"i","Ñ":"N","ñ":"n","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ø":"O","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","Ù":"U","Ú":"U","Û":"U","Ü":"U","ù":"u","ú":"u","û":"u","ü":"u","Ý":"Y","ý":"y","ÿ":"y","Æ":"Ae","æ":"ae","Þ":"Th","þ":"th","ß":"ss","Ā":"A","Ă":"A","Ą":"A","ā":"a","ă":"a","ą":"a","Ć":"C","Ĉ":"C","Ċ":"C","Č":"C","ć":"c","ĉ":"c","ċ":"c","č":"c","Ď":"D","Đ":"D","ď":"d","đ":"d","Ē":"E","Ĕ":"E","Ė":"E","Ę":"E","Ě":"E","ē":"e","ĕ":"e","ė":"e","ę":"e","ě":"e","Ĝ":"G","Ğ":"G","Ġ":"G","Ģ":"G","ĝ":"g","ğ":"g","ġ":"g","ģ":"g","Ĥ":"H","Ħ":"H","ĥ":"h","ħ":"h","Ĩ":"I","Ī":"I","Ĭ":"I","Į":"I","İ":"I","ĩ":"i","ī":"i","ĭ":"i","į":"i","ı":"i","Ĵ":"J","ĵ":"j","Ķ":"K","ķ":"k","ĸ":"k","Ĺ":"L","Ļ":"L","Ľ":"L","Ŀ":"L","Ł":"L","ĺ":"l","ļ":"l","ľ":"l","ŀ":"l","ł":"l","Ń":"N","Ņ":"N","Ň":"N","Ŋ":"N","ń":"n","ņ":"n","ň":"n","ŋ":"n","Ō":"O","Ŏ":"O","Ő":"O","ō":"o","ŏ":"o","ő":"o","Ŕ":"R","Ŗ":"R","Ř":"R","ŕ":"r","ŗ":"r","ř":"r","Ś":"S","Ŝ":"S","Ş":"S","Š":"S","ś":"s","ŝ":"s","ş":"s","š":"s","Ţ":"T","Ť":"T","Ŧ":"T","ţ":"t","ť":"t","ŧ":"t","Ũ":"U","Ū":"U","Ŭ":"U","Ů":"U","Ű":"U","Ų":"U","ũ":"u","ū":"u","ŭ":"u","ů":"u","ű":"u","ų":"u","Ŵ":"W","ŵ":"w","Ŷ":"Y","ŷ":"y","Ÿ":"Y","Ź":"Z","Ż":"Z","Ž":"Z","ź":"z","ż":"z","ž":"z","IJ":"IJ","ij":"ij","Œ":"Oe","œ":"oe","ʼn":"'n","ſ":"ss"}),k=Object.prototype.toString,F=O.Symbol,U=F?F.prototype:void 0,_=U?U.toString:void 0;function C(e){return null==e?"":function(e){if("string"==typeof e)return e;if(function(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&k.call(e)==r}(e))return _?_.call(e):"";var t=e+"";return"0"==t&&1/e==-n?"-0":t}(e)}var T=function(e){return function(t){return function(e,t,n,r){for(var o=-1,i=e?e.length:0;++o<i;)n=t(n,e[o],o,e);return n}(function(e,t,n){return e=C(e),void 0===(t=t)?function(e){return S.test(e)}(e)?function(e){return e.match(A)||[]}(e):function(e){return e.match(o)||[]}(e):e.match(t)||[]}(function(e){return(e=C(e))&&e.replace(i,w).replace(h,"")}(t).replace(x,"")),e,"")}}(function(e,t,n){return e+(n?"_":"")+t.toLowerCase()});e.exports=T}).call(this,n(5))},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.initializeSegment=function(e){var t=window.analytics=window.analytics||[];if(!t.initialize)if(t.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{t.invoked=!0,t.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on"],t.factory=function(e){return function(){var n=Array.prototype.slice.call(arguments);return n.unshift(e),t.push(n),t}};for(var n=0;n<t.methods.length;n++){var r=t.methods[n];t[r]=t.factory(r)}t.load=function(e,n){var r=document.createElement("script");r.type="text/javascript",r.async=!0,r.src="https://cdn.segment.com/analytics.js/v1/"+e+"/analytics.min.js";var o=document.getElementsByTagName("script")[0];o.parentNode.insertBefore(r,o),t._loadOptions=n},t.SNIPPET_VERSION="4.1.0",t.load(e)}}}])}); | ||
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports["frontend-analytics"]=n():e["frontend-analytics"]=n()}("undefined"!=typeof self?self:this,function(){return function(e){var n={};function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(n){return e[n]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=0)}([function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.sendTrackingLogEvent=n.sendTrackEvent=n.sendPageEvent=n.initializeSegment=n.identifyAuthenticatedUser=n.identifyAnonymousUser=n.configureAnalytics=void 0;var r=t(1),o=t(6);n.configureAnalytics=r.configureAnalytics,n.identifyAnonymousUser=r.identifyAnonymousUser,n.identifyAuthenticatedUser=r.identifyAuthenticatedUser,n.initializeSegment=o.initializeSegment,n.sendPageEvent=r.sendPageEvent,n.sendTrackEvent=r.sendTrackEvent,n.sendTrackingLogEvent=r.sendTrackingLogEvent},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.sendTrackingLogEvent=n.sendTrackEvent=n.sendPageEvent=n.identifyAuthenticatedUser=n.identifyAnonymousUser=n.configureAnalytics=void 0;var r=function(e){return e&&e.__esModule?e:{default:e}}(t(2)),o=t(3),i={},u=!1;function f(){if(!i.loggingService)throw Error("You must configure the loggingService.");return i.loggingService}function c(){var e=f();u||e.logError("Identify must be called before other tracking events.")}n.configureAnalytics=function(e){u=!1,i={loggingService:e.loggingService,authApiClient:e.authApiClient,analyticsApiBaseUrl:e.analyticsApiBaseUrl}},n.identifyAnonymousUser=function(e){window.analytics.identify(e),u=!0},n.identifyAuthenticatedUser=function(e,n){window.analytics.identify(e,n),u=!0},n.sendPageEvent=function(e,n,t){c(),window.analytics.page(e,n,t)},n.sendTrackEvent=function(e,n){c(),window.analytics.track(e,n)},n.sendTrackingLogEvent=function(e,n){var t=(0,o.snakeCaseObject)(n,{deep:!0}),u={event_type:e,event:JSON.stringify(t),page:window.location.href},c=f();return function(){if(!i.authApiClient)throw Error("You must configure the authApiClient.");return i.authApiClient}().post(i.analyticsApiBaseUrl+"/event",(0,r.default)(u),{headers:{"Content-Type":"application/x-www-form-urlencoded"}}).catch(function(e){c.logAPIErrorResponse(e)})}},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};n.default=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=Boolean(n.sorted),o=Boolean(n.skipIndex),i=Boolean(n.ignorenull),u=function(e){return String(e).replace(/(?:[\0-\x1F"-&\+-\}\x7F-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])/g,encodeURIComponent).replace(/ /g,"+").replace(/[!'()~\*]/g,function(e){return"%"+e.charCodeAt().toString(16).slice(-2).toUpperCase()})},f=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Object.keys(e);return t?n.sort():n},c=function(e){return e.filter(function(e){return e}).join("&")},a=function(e,n){return n.length?c(n.map(function(n,t){return l(o?e+"[]":e+"["+t+"]",n)})):u(e+"[]")},l=function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0===n?"undefined":r(n),o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;return n===o?o=i?o:u(e)+"="+o:/string|number|boolean/.test(t)?o=u(e)+"="+u(n):Array.isArray(n)?o=a(e,n):"object"===t&&(o=function(e,n){return c(f(n).map(function(t){return l(e+"["+t+"]",n[t])}))}(e,n)),o};return e&&c(f(e).map(function(n){return l(n,e[n])}))}},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.snakeCaseObject=void 0;var r=function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,n){var t=[],r=!0,o=!1,i=void 0;try{for(var u,f=e[Symbol.iterator]();!(r=(u=f.next()).done)&&(t.push(u.value),!n||t.length!==n);r=!0);}catch(e){o=!0,i=e}finally{try{!r&&f.return&&f.return()}finally{if(o)throw i}}return t}(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")},o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=function(e){return e&&e.__esModule?e:{default:e}}(t(4));n.snakeCaseObject=function(e){return function e(n,t){if(null==n||"object"!==(void 0===n?"undefined":o(n))&&!Array.isArray(n))return n;if(Array.isArray(n))return n.map(function(n){return e(n,t)});var i={};return Object.entries(n).forEach(function(n){var o=r(n,2),u=o[0],f=o[1];i[t(u)]=e(f,t)}),i}(e,i.default)}},function(e,n,t){(function(n){var t=1/0,r="[object Symbol]",o=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,i=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,u="\\xac\\xb1\\xd7\\xf7\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\u2000-\\u206f \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",f="["+u+"]",c="\\d+",a="[a-z\\xdf-\\xf6\\xf8-\\xff]",l="[^\\ud800-\\udfff"+u+c+"\\u2700-\\u27bfa-z\\xdf-\\xf6\\xf8-\\xffA-Z\\xc0-\\xd6\\xd8-\\xde]",s="(?:\\ud83c[\\udde6-\\uddff]){2}",d="[\\ud800-\\udbff][\\udc00-\\udfff]",y="[A-Z\\xc0-\\xd6\\xd8-\\xde]",p="(?:"+a+"|"+l+")",g="(?:"+y+"|"+l+")",v="(?:[\\u0300-\\u036f\\ufe20-\\ufe23\\u20d0-\\u20f0]|\\ud83c[\\udffb-\\udfff])?",b="[\\ufe0e\\ufe0f]?"+v+"(?:\\u200d(?:"+["[^\\ud800-\\udfff]",s,d].join("|")+")[\\ufe0e\\ufe0f]?"+v+")*",m="(?:"+["[\\u2700-\\u27bf]",s,d].join("|")+")"+b,x=RegExp("['’]","g"),h=RegExp("[\\u0300-\\u036f\\ufe20-\\ufe23\\u20d0-\\u20f0]","g"),A=RegExp([y+"?"+a+"+(?:['’](?:d|ll|m|re|s|t|ve))?(?="+[f,y,"$"].join("|")+")",g+"+(?:['’](?:D|LL|M|RE|S|T|VE))?(?="+[f,y+p,"$"].join("|")+")",y+"?"+p+"+(?:['’](?:d|ll|m|re|s|t|ve))?",y+"+(?:['’](?:D|LL|M|RE|S|T|VE))?",c,m].join("|"),"g"),j=/[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,S="object"==typeof n&&n&&n.Object===Object&&n,E="object"==typeof self&&self&&self.Object===Object&&self,O=S||E||Function("return this")(),w=function(e){return function(n){return null==e?void 0:e[n]}}({"À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","Ç":"C","ç":"c","Ð":"D","ð":"d","È":"E","É":"E","Ê":"E","Ë":"E","è":"e","é":"e","ê":"e","ë":"e","Ì":"I","Í":"I","Î":"I","Ï":"I","ì":"i","í":"i","î":"i","ï":"i","Ñ":"N","ñ":"n","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ø":"O","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","Ù":"U","Ú":"U","Û":"U","Ü":"U","ù":"u","ú":"u","û":"u","ü":"u","Ý":"Y","ý":"y","ÿ":"y","Æ":"Ae","æ":"ae","Þ":"Th","þ":"th","ß":"ss","Ā":"A","Ă":"A","Ą":"A","ā":"a","ă":"a","ą":"a","Ć":"C","Ĉ":"C","Ċ":"C","Č":"C","ć":"c","ĉ":"c","ċ":"c","č":"c","Ď":"D","Đ":"D","ď":"d","đ":"d","Ē":"E","Ĕ":"E","Ė":"E","Ę":"E","Ě":"E","ē":"e","ĕ":"e","ė":"e","ę":"e","ě":"e","Ĝ":"G","Ğ":"G","Ġ":"G","Ģ":"G","ĝ":"g","ğ":"g","ġ":"g","ģ":"g","Ĥ":"H","Ħ":"H","ĥ":"h","ħ":"h","Ĩ":"I","Ī":"I","Ĭ":"I","Į":"I","İ":"I","ĩ":"i","ī":"i","ĭ":"i","į":"i","ı":"i","Ĵ":"J","ĵ":"j","Ķ":"K","ķ":"k","ĸ":"k","Ĺ":"L","Ļ":"L","Ľ":"L","Ŀ":"L","Ł":"L","ĺ":"l","ļ":"l","ľ":"l","ŀ":"l","ł":"l","Ń":"N","Ņ":"N","Ň":"N","Ŋ":"N","ń":"n","ņ":"n","ň":"n","ŋ":"n","Ō":"O","Ŏ":"O","Ő":"O","ō":"o","ŏ":"o","ő":"o","Ŕ":"R","Ŗ":"R","Ř":"R","ŕ":"r","ŗ":"r","ř":"r","Ś":"S","Ŝ":"S","Ş":"S","Š":"S","ś":"s","ŝ":"s","ş":"s","š":"s","Ţ":"T","Ť":"T","Ŧ":"T","ţ":"t","ť":"t","ŧ":"t","Ũ":"U","Ū":"U","Ŭ":"U","Ů":"U","Ű":"U","Ų":"U","ũ":"u","ū":"u","ŭ":"u","ů":"u","ű":"u","ų":"u","Ŵ":"W","ŵ":"w","Ŷ":"Y","ŷ":"y","Ÿ":"Y","Ź":"Z","Ż":"Z","Ž":"Z","ź":"z","ż":"z","ž":"z","IJ":"IJ","ij":"ij","Œ":"Oe","œ":"oe","ʼn":"'n","ſ":"ss"}),k=Object.prototype.toString,F=O.Symbol,U=F?F.prototype:void 0,_=U?U.toString:void 0;function C(e){return null==e?"":function(e){if("string"==typeof e)return e;if(function(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&k.call(e)==r}(e))return _?_.call(e):"";var n=e+"";return"0"==n&&1/e==-t?"-0":n}(e)}var T=function(e){return function(n){return function(e,n,t,r){for(var o=-1,i=e?e.length:0;++o<i;)t=n(t,e[o],o,e);return t}(function(e,n,t){return e=C(e),void 0===(n=n)?function(e){return j.test(e)}(e)?function(e){return e.match(A)||[]}(e):function(e){return e.match(o)||[]}(e):e.match(n)||[]}(function(e){return(e=C(e))&&e.replace(i,w).replace(h,"")}(n).replace(x,"")),e,"")}}(function(e,n,t){return e+(t?"_":"")+n.toLowerCase()});e.exports=T}).call(this,t(5))},function(e,n){var t;t=function(){return this}();try{t=t||new Function("return this")()}catch(e){"object"==typeof window&&(t=window)}e.exports=t},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.initializeSegment=function(e){var n=window.analytics=window.analytics||[];if(!n.initialize)if(n.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{n.invoked=!0,n.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on"],n.factory=function(e){return function(){var t=Array.prototype.slice.call(arguments);return t.unshift(e),n.push(t),n}};for(var t=0;t<n.methods.length;t++){var r=n.methods[t];n[r]=n.factory(r)}n.load=function(e,t){var r=document.createElement("script");r.type="text/javascript",r.async=!0,r.src="https://cdn.segment.com/analytics.js/v1/"+e+"/analytics.min.js";var o=document.getElementsByTagName("script")[0];o.parentNode.insertBefore(r,o),n._loadOptions=t},n.SNIPPET_VERSION="4.1.0",n.load(e)}}}])}); | ||
//# sourceMappingURL=main.js.map |
{ | ||
"name": "@edx/frontend-analytics", | ||
"version": "1.0.4", | ||
"version": "2.0.0", | ||
"description": "Frontend analytics client code for sending analytics events to Segment and (LMS) Tracking Logs.", | ||
@@ -5,0 +5,0 @@ "main": "dist/main.js", |
@@ -79,17 +79,9 @@ import formurlencoded from 'form-urlencoded'; | ||
/** | ||
* Send identify call to Segment, using userId from authApiClient. | ||
* Send identify call to Segment. | ||
* @param userId | ||
* @param traits (optional) | ||
*/ | ||
function identifyAuthenticatedUser(traits) { | ||
const apiClient = getAuthApiClient(); | ||
const authState = apiClient.getAuthenticationState(); | ||
const loggingService = getLoggingService(); // verifies configuration early | ||
if (authState.authentication && authState.authentication.userId) { | ||
// eslint-disable-next-line no-undef | ||
window.analytics.identify(authState.authentication.userId, traits); | ||
hasIdentifyBeenCalled = true; | ||
} else { | ||
const details = `authState: ${JSON.stringify(authState)} cookies: ${document.cookie}`; | ||
loggingService.logError(`Failed to sendAuthenticatedIdentify. ${details}`); | ||
} | ||
function identifyAuthenticatedUser(userId, traits) { | ||
window.analytics.identify(userId, traits); | ||
hasIdentifyBeenCalled = true; | ||
} | ||
@@ -96,0 +88,0 @@ |
@@ -39,11 +39,2 @@ import { | ||
function createMockAuthApiClientAuthenticationIncomplete() { | ||
mockAuthApiClient = { | ||
getAuthenticationState: | ||
jest.fn(() => ({ | ||
authentication: {}, | ||
})), | ||
}; | ||
} | ||
function createMockAuthApiClientPostResolved() { | ||
@@ -126,27 +117,7 @@ mockAuthApiClient = { | ||
it('fails when loggingService is not configured', () => { | ||
mockLoggingService = undefined; | ||
createMockAuthApiClientAuthenticated(); | ||
configureAnalyticsWithMocks(); | ||
expect(() => identifyAuthenticatedUser()) | ||
.toThrowError('You must configure the loggingService.'); | ||
}); | ||
it('fails when authApiClient is not configured', () => { | ||
createMockLoggingService(); | ||
mockAuthApiClient = undefined; | ||
configureAnalyticsWithMocks(); | ||
expect(() => identifyAuthenticatedUser()) | ||
.toThrowError('You must configure the authApiClient.'); | ||
}); | ||
it('calls Segment identify on success', () => { | ||
createMockLoggingService(); | ||
createMockAuthApiClientAuthenticated(); | ||
configureAnalyticsWithMocks(); | ||
const testTraits = { anything: 'Yay!' }; | ||
identifyAuthenticatedUser(testTraits); | ||
identifyAuthenticatedUser(testUserId, testTraits); | ||
@@ -156,12 +127,2 @@ expect(window.analytics.identify.mock.calls.length).toBe(1); | ||
}); | ||
it('logs error when authentication problem.', () => { | ||
createMockLoggingService(); | ||
createMockAuthApiClientAuthenticationIncomplete(); | ||
configureAnalyticsWithMocks(); | ||
identifyAuthenticatedUser(); | ||
expect(mockLoggingService.logError.mock.calls.length).toBe(1); | ||
}); | ||
}); | ||
@@ -168,0 +129,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
111370
546