Last active
April 14, 2021 21:43
-
-
Save phylliswong/67a80a01def03c105b09f0492c5d5d21 to your computer and use it in GitHub Desktop.
TruGreen GA Integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function () { | |
var Evolv=function(t){"use strict";var e=function(t,i){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])})(t,i)};function i(t,i){function n(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}var n=function(){function t(t){void 0===t&&(t=5e3),this.maxWaitTime=t,this.queue=[],this.interval=50,this.activeCandidateEvents={confirmed:{},contaminated:{}},this.contaminations={},this.waitForAnalytics(),this.waitForEvolv(this.configureListeners.bind(this))}return t.prototype.configureListeners=function(){var t=this;window.evolv.client.on("confirmed",(function(e){t.sendMetricsForActiveCandidates(e)})),window.evolv.client.on("contaminated",(function(e){t.sendMetricsForActiveCandidates(e)})),window.evolv.client.on("event.emitted",(function(e,i){t.sendMetrics(i,{uid:window.evolv.context.uid})}))},t.prototype.sendMetricsForActiveCandidates=function(t){for(var e,i=this.getContextKey(t),n=this.getEvolv().context.get(i)||[],o=0;o<n.length;o++)if(this.activeCandidateEvents[t]&&!this.activeCandidateEvents[t][null===(e=null==n?void 0:n[o])||void 0===e?void 0:e.cid]){var r=this.lookupFromAllocations(n[o].cid);this.sendMetrics(t,r),this.activeCandidateEvents[t][n[o].cid]=!0}},t.prototype.lookupFromAllocations=function(t){for(var e=this.getEvolv().context.get("experiments").allocations,i=0;i<e.length;i++){var n=e[i];if(n.cid===t)return n}},t.prototype.getContextKey=function(t){switch(t){case"confirmed":return"experiments.confirmations";case"contaminated":return"experiments.contaminations";default:return""}},t.prototype.getEvolv=function(){return window.evolv},t.prototype.getHandler=function(){return this.getAnalytics()},t.prototype.waitForEvolv=function(t){var e=this;if(this.getEvolv())t&&t();else var i=Date.now(),n=setInterval((function(){if(Date.now()-i>e.maxWaitTime)return clearInterval(n),void console.log("Evolv: Analytics integration timed out - couldn't find Evolv");e.getEvolv()&&(t&&t(),clearInterval(n))}),this.interval)},t.prototype.waitForAnalytics=function(){var t=this;if(!this.getAnalytics())var e=Date.now(),i=setInterval((function(){if(Date.now()-e>t.maxWaitTime)return clearInterval(i),console.log("Evolv: Analytics integration timed out - Couldn't find Analytics"),void t.checkAnalyticsProviders();var n=t.getHandler();if(n){for(var o;t.queue.length;)o=t.queue.shift(),n.apply(void 0,o);clearInterval(i)}}),this.interval)},t.prototype.getAugmentedOrdinal=function(t){if(t.ordinal)return"ordinal-"+t.ordinal},t.prototype.getAugmentedGroupId=function(t){if(t.group_id)return"gid-"+t.group_id},t.prototype.getAugmentedCidEid=function(t){var e;if(t.cid){var i=t.cid.split(":");e="cid-"+i[0]+":eid-"+i[1];var n=i.slice(2).join(":");n&&(e=e+":"+n)}else e="";return e},t.prototype.getAugmentedUid=function(t){var e="";return t.uid&&(e="uid-"+t.uid),e},t.prototype.getAugmentedSid=function(){var t="";return window.evolv.context.sid&&(t="sid-"+window.evolv.context.sid),t},t.prototype.emit=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var i=this.getAnalytics();i?i.apply(void 0,t):this.queue.push(t)},t}(),o=function(t){function e(e,i,n,o){void 0===n&&(n=5e3),void 0===o&&(o=!1);var r=t.call(this,n)||this;return r.trackingId=e,r.namespace=i,r.maxWaitTime=n,r.includeCidEid=o,r}return i(e,t),e.prototype.getAnalytics=function(){return window.GoogleAnalyticsObject&&window[window.GoogleAnalyticsObject]||window.ga},e.prototype.checkAnalyticsProviders=function(){(window.google_tag_manager||window.gtag)&&console.log("Evolv: Analytics integration detected Google Tag Manager - please use 'Evolv.GtagClient()'")},e.prototype.sendMetrics=function(t,e){var i=this.namespace,n=i?i+".":"",o=this.getAugmentedSid(),r=this.getAugmentedUid(e),a=this.getAugmentedCidEid(e),c=this.getAugmentedGroupId(e),d=this.getAugmentedOrdinal(e);this.emit("create",this.trackingId,"auto",i?{namespace:i}:null);var s;d?(s="evolv-event:"+c+":"+d,this.includeCidEid&&(s+=":"+a)):s=a?"evolv-event:"+a:"evolv-event",this.emit(n+"send","event",{eventCategory:"evolvids",eventAction:s,eventLabel:t+":"+r+":"+o,nonInteraction:!0})},e}(n),r=function(t){function e(e,i){void 0===e&&(e=5e3),void 0===i&&(i=!1);var n=t.call(this,e)||this;return n.maxWaitTime=e,n.includeCidEid=i,n}return i(e,t),e.prototype.getAnalytics=function(){return window.gtag},e.prototype.checkAnalyticsProviders=function(){(window.GoogleAnalyticsObject&&window[window.GoogleAnalyticsObject]||window.ga)&&console.log("Evolv: Analytics integration detected GA - please use 'Evolv.GAClient()'")},e.prototype.sendMetrics=function(t,e){var i={non_interaction:!0},n=this.getAugmentedSid(),o=this.getAugmentedCidEid(e),r=this.getAugmentedUid(e),a=this.getAugmentedGroupId(e),c=this.getAugmentedOrdinal(e);i.event_category="evolvids",i.event_label=t+":"+r+":"+n;var d;c?(d="evolv-event:"+a+":"+c,this.includeCidEid&&(d+=":"+o)):d="evolv-event:"+o,this.emit("event",o?d:"evolv-event",i)},e}(n);return t.GAClient=o,t.GtagClient=r,t}({}); | |
const client = new Evolv.GAClient("UA-21020305-4", "", 15000, false); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "evolv-trugreen-ga3-integration", | |
"version": "1.0.0", | |
"main": "index.js" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment