From ec2448b772a7e7767058bcfd56f1a9fa6cb4891b Mon Sep 17 00:00:00 2001 From: Chris Alme Date: Tue, 26 Feb 2019 12:06:22 -0600 Subject: [PATCH 01/27] PNIX-1763 - Build and deployment plan for Clario Snowplow javascript Initial checkin for Snowplow customization (current impl in Plowio repo in bitbucket). --- src/js/clario.js | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ src/js/init.js | 49 ++++++++++++++++++---------------- 2 files changed, 95 insertions(+), 23 deletions(-) create mode 100644 src/js/clario.js diff --git a/src/js/clario.js b/src/js/clario.js new file mode 100644 index 000000000..4530e54b3 --- /dev/null +++ b/src/js/clario.js @@ -0,0 +1,69 @@ +;(function() { + window.snowplow("newTracker", "cf", "c.clario.us", { + appId: window.clarioTrackerData.app_id, + platform: "web", + discoverRootDomain: true, + post: true, + contexts: { + webPage: true, + performanceTiming: true, + gaCookies: true, + geolocation: false + } + }); + + window.snowplow('setUserId', window.clarioTrackerData.customer_id); + + (function() { + var hits = []; + var allTheCookies = document.cookie.split(";"); + ["_fbp", "_ga"].forEach(function(term) { + var found = allTheCookies.find(function(cookie) { + return cookie.indexOf(term + "=") >= 0; + }); + if (found) { + var parts = found.split("="); + if (parts.length == 2) { + hits.push({ + name: term, + value: parts[1] + }); + } + } + }); + + if (hits.length) { + window.snowplow('trackPageView', null, [{ + schema: "iglu:io.clar/cookies/jsonschema/2-0-0", + data: { + cookies: hits + } + }]); + } else { + window.snowplow('trackPageView'); + } + })(); + + if (window.clarioTrackerData.order_id) { + window.snowplow('addTrans', + window.clarioTrackerData.order_id, + window.clarioTrackerData.order_affiliation, + window.clarioTrackerData.order_total + ); + + if (window.clarioTrackerData.order_items) { + window.clarioTrackerData.order_items.forEach(function(item) { + window.snowplow('addItem', + item.orderId, + item.sku, + item.name, + '', + item.price, + item.quantity + ); + }); + } + + window.snowplow('trackTrans'); + } +}()); diff --git a/src/js/init.js b/src/js/init.js index 9e243b192..7210f0d59 100644 --- a/src/js/init.js +++ b/src/js/init.js @@ -1,34 +1,34 @@ /* * JavaScript tracker for Snowplow: init.js - * - * Significant portions copyright 2010 Anthon Pang. Remainder copyright - * 2012-2014 Snowplow Analytics Ltd. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * Significant portions copyright 2010 Anthon Pang. Remainder copyright + * 2012-2014 Snowplow Analytics Ltd. All rights reserved. * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. * * * Neither the name of Anthon Pang nor Snowplow Analytics Ltd nor the * names of their contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. + * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -38,6 +38,9 @@ * Get the name of the global input function */ +// Inject Clario stuff first +require('./clario'); + var snowplow = require('./snowplow'), queueName, queue, From abe05ca6a971b10c4f8fc98ad0d06366dd65204e Mon Sep 17 00:00:00 2001 From: Chris Alme Date: Tue, 16 Apr 2019 11:26:50 -0500 Subject: [PATCH 02/27] PNIX-1882 - Snowplow - Add shipping, tax, and line item detail tax/shipping impl, need to update deployed tags to pass this info now. --- src/js/clario.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/js/clario.js b/src/js/clario.js index 4530e54b3..781fbe662 100644 --- a/src/js/clario.js +++ b/src/js/clario.js @@ -48,7 +48,9 @@ window.snowplow('addTrans', window.clarioTrackerData.order_id, window.clarioTrackerData.order_affiliation, - window.clarioTrackerData.order_total + window.clarioTrackerData.order_total, + window.clarioTrackerData.order_tax || "", + window.clarioTrackerData.order_shipping || "" ); if (window.clarioTrackerData.order_items) { From e3a7f4bec9899bf2e3ab023a987bbbf4e59a517b Mon Sep 17 00:00:00 2001 From: Chris Alme Date: Mon, 22 Apr 2019 10:06:56 -0500 Subject: [PATCH 03/27] PNIX-1882 - Snowplow - Add shipping, tax, and line item detail Adding tax/shipping as well as "transaction" custom context to pass transaction related items (e.g. promo/coupon/etc) with an order. --- src/js/clario.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/js/clario.js b/src/js/clario.js index 781fbe662..bb47d498d 100644 --- a/src/js/clario.js +++ b/src/js/clario.js @@ -45,12 +45,26 @@ })(); if (window.clarioTrackerData.order_id) { + var context = null; + if (window.clarioTrackerData.order_context) { + context = [{ + schema: "iglu:io.clar/transaction/jsonschema/1-0-0", + data: { + transaction: window.clarioTrackerData.order_context + } + }] + } window.snowplow('addTrans', window.clarioTrackerData.order_id, window.clarioTrackerData.order_affiliation, window.clarioTrackerData.order_total, window.clarioTrackerData.order_tax || "", - window.clarioTrackerData.order_shipping || "" + window.clarioTrackerData.order_shipping || "", + "", + "", + "", + "", + context ); if (window.clarioTrackerData.order_items) { From 278dbac3e7f3ae932eb979e5e34a822ebd414485 Mon Sep 17 00:00:00 2001 From: Chris Alme Date: Tue, 23 Apr 2019 15:02:45 -0500 Subject: [PATCH 04/27] PNIX-1882 - Snowplow - Add shipping, tax, and line item detail Adding transaction context handling at the order line item level. --- src/js/clario.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/js/clario.js b/src/js/clario.js index bb47d498d..061b69f49 100644 --- a/src/js/clario.js +++ b/src/js/clario.js @@ -73,9 +73,11 @@ item.orderId, item.sku, item.name, - '', + "", item.price, - item.quantity + item.quantity, + "", + item.context || "" ); }); } From 3e87cb9584790a50972529b7b903a96a8e37ab78 Mon Sep 17 00:00:00 2001 From: Dan Reiland Date: Fri, 11 Oct 2019 12:56:55 -0500 Subject: [PATCH 05/27] PNIX-2011 - Criteo GUM tracker - Initial impl --- src/js/clario.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/js/clario.js b/src/js/clario.js index 061b69f49..f270d32df 100644 --- a/src/js/clario.js +++ b/src/js/clario.js @@ -1,5 +1,5 @@ ;(function() { - window.snowplow("newTracker", "cf", "c.clario.us", { + window.snowplow("newTracker", "cf", window.clarioTrackerData.collector || "c.clario.us", { appId: window.clarioTrackerData.app_id, platform: "web", discoverRootDomain: true, @@ -44,6 +44,7 @@ } })(); + if (window.clarioTrackerData.order_id) { var context = null; if (window.clarioTrackerData.order_context) { @@ -83,5 +84,28 @@ } window.snowplow('trackTrans'); + }; + + if (window.clarioTrackerData.gumEnabled) { + try { + var gumUrl = "https://gum.criteo.com/sync?c=" + window.ClarioTrackerData.gum_id + "&r=1&a=1&u="; + + var redirectUrl = + "https://" + + window.clarioTrackerData.collector + + "/i?aid=" + + window.clarioTrackerData.app_id + + "&e=se&p=web&tv=2.10.2&se_ca=criteo&se_ac=cookie_match&se_la=" + + // domainUserId + (""+document.cookie.split(";").find(function(cookie){return cookie.search(/_sp_id\..*=/) >= 0;})).split("=")[1].split(".")[0] + + "&se_pr=@USERID@"; + + var xhr = new XMLHttpRequest(); + xhr.open('GET', gumUrl + encodeURIComponent(redirectUrl),true); + xhr.withCredentials = true; + xhr.send(); + } catch { + console.log("Error sending GUM request.") + } } }()); From b186ff98ed0922b7066f0ad05cab0797066366f6 Mon Sep 17 00:00:00 2001 From: Dan Reiland Date: Fri, 11 Oct 2019 13:10:34 -0500 Subject: [PATCH 06/27] PNIX-2011 - Criteo GUM tracker - Now using clarioTrackerData.gum_id instead of gumEnabled --- src/js/clario.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/clario.js b/src/js/clario.js index f270d32df..41262c3b1 100644 --- a/src/js/clario.js +++ b/src/js/clario.js @@ -84,9 +84,9 @@ } window.snowplow('trackTrans'); - }; + } - if (window.clarioTrackerData.gumEnabled) { + if (window.clarioTrackerData.gum_id) { try { var gumUrl = "https://gum.criteo.com/sync?c=" + window.ClarioTrackerData.gum_id + "&r=1&a=1&u="; From b9122f0a0385f6a212e72f48eea0e2979afe5950 Mon Sep 17 00:00:00 2001 From: Dan Reiland Date: Fri, 11 Oct 2019 14:53:27 -0500 Subject: [PATCH 07/27] PNIX-2011 - Criteo GUM tracker - Fixed issue in gum_id variable name --- src/js/clario.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/clario.js b/src/js/clario.js index 41262c3b1..559d7487b 100644 --- a/src/js/clario.js +++ b/src/js/clario.js @@ -88,7 +88,7 @@ if (window.clarioTrackerData.gum_id) { try { - var gumUrl = "https://gum.criteo.com/sync?c=" + window.ClarioTrackerData.gum_id + "&r=1&a=1&u="; + var gumUrl = "https://gum.criteo.com/sync?c=" + window.clarioTrackerData.gum_id + "&r=1&a=1&u="; var redirectUrl = "https://" + From f5b0a99aea8b8164ec1e05588e56d0e0b3c89006 Mon Sep 17 00:00:00 2001 From: Dan Reiland Date: Fri, 11 Oct 2019 16:04:12 -0500 Subject: [PATCH 08/27] PNIX-2011 - Criteo GUM tracker - Address case where gum_id is set, but collector endpoint isn't --- src/js/clario.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/clario.js b/src/js/clario.js index 559d7487b..b4233f860 100644 --- a/src/js/clario.js +++ b/src/js/clario.js @@ -92,7 +92,7 @@ var redirectUrl = "https://" + - window.clarioTrackerData.collector + + window.clarioTrackerData.collector || "c.clario.us" + "/i?aid=" + window.clarioTrackerData.app_id + "&e=se&p=web&tv=2.10.2&se_ca=criteo&se_ac=cookie_match&se_la=" + From 152166ee0a3a86001b1428450dcf0f62d929ad01 Mon Sep 17 00:00:00 2001 From: Dan Reiland Date: Fri, 11 Oct 2019 16:11:54 -0500 Subject: [PATCH 09/27] PNIX-2011 - Criteo GUM tracker - Address case where gum_id is set, but collector endpoint isn't --- src/js/clario.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/js/clario.js b/src/js/clario.js index b4233f860..e3a155e77 100644 --- a/src/js/clario.js +++ b/src/js/clario.js @@ -88,11 +88,13 @@ if (window.clarioTrackerData.gum_id) { try { + + var collector = window.clarioTrackerData.collector || "c.clario.us"; var gumUrl = "https://gum.criteo.com/sync?c=" + window.clarioTrackerData.gum_id + "&r=1&a=1&u="; var redirectUrl = "https://" + - window.clarioTrackerData.collector || "c.clario.us" + + collector + "/i?aid=" + window.clarioTrackerData.app_id + "&e=se&p=web&tv=2.10.2&se_ca=criteo&se_ac=cookie_match&se_la=" + From b5f4bacc71eb4dbb30695e3439227a7775917d86 Mon Sep 17 00:00:00 2001 From: Dan Reiland Date: Tue, 26 Nov 2019 16:00:22 -0600 Subject: [PATCH 10/27] PNIX-2038 - Snowplow - Tag - Multiple Domain Tracker - Impl - Updated tag to 2.12.0 release - Set stateStorageStrategy to localStorage - Updated Criteo GUM match function to pull Snowplow session ID from either local storage or cookie --- src/js/clario.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/js/clario.js b/src/js/clario.js index e3a155e77..4b207efcd 100644 --- a/src/js/clario.js +++ b/src/js/clario.js @@ -3,6 +3,7 @@ appId: window.clarioTrackerData.app_id, platform: "web", discoverRootDomain: true, + stateStorageStrategy: "localStorage", post: true, contexts: { webPage: true, @@ -92,14 +93,23 @@ var collector = window.clarioTrackerData.collector || "c.clario.us"; var gumUrl = "https://gum.criteo.com/sync?c=" + window.clarioTrackerData.gum_id + "&r=1&a=1&u="; + Object.keys(localStorage).forEach(function(key){ if (key.search(/_sp_id\.\w/) >= 0) + { + window.clarioTrackerData.sp_id = localStorage.getItem(key); + } + }); + + if (!window.clarioTrackerData.sp_id) { + window.clarioTrackerData.sp_id = document.cookie.split(";").find(function(cookie){return cookie.search(/_sp_id\..*=/) >= 0;}).split("=")[1].split(".")[0]; + } + var redirectUrl = "https://" + collector + "/i?aid=" + window.clarioTrackerData.app_id + "&e=se&p=web&tv=2.10.2&se_ca=criteo&se_ac=cookie_match&se_la=" + - // domainUserId - (""+document.cookie.split(";").find(function(cookie){return cookie.search(/_sp_id\..*=/) >= 0;})).split("=")[1].split(".")[0] + + window.clarioTrackerData.sp_id || "" + "&se_pr=@USERID@"; var xhr = new XMLHttpRequest(); From cf1f3213c1d1d7fa5ffff0433f70fdd0a1f487fb Mon Sep 17 00:00:00 2001 From: Dan Reiland Date: Mon, 30 Dec 2019 14:28:33 -0600 Subject: [PATCH 11/27] PNIX-2096 - Snowplow - Single Page Apps - Events Not Firing - Wrapped page view, transaction, and gum match in functions - Added location change event handlers to facilitate tracking in SPAs --- src/js/clario.js | 179 +++++++++++++++++++++++++++++------------------ 1 file changed, 109 insertions(+), 70 deletions(-) diff --git a/src/js/clario.js b/src/js/clario.js index 4b207efcd..fb4ad5301 100644 --- a/src/js/clario.js +++ b/src/js/clario.js @@ -13,13 +13,13 @@ } }); - window.snowplow('setUserId', window.clarioTrackerData.customer_id); + var trackIt = function () { + window.snowplow('setUserId', window.clarioTrackerData.customer_id); - (function() { var hits = []; var allTheCookies = document.cookie.split(";"); - ["_fbp", "_ga"].forEach(function(term) { - var found = allTheCookies.find(function(cookie) { + ["_fbp", "_ga"].forEach(function (term) { + var found = allTheCookies.find(function (cookie) { return cookie.indexOf(term + "=") >= 0; }); if (found) { @@ -43,81 +43,120 @@ } else { window.snowplow('trackPageView'); } - })(); + } + var orderUp = function () { + if (window.clarioTrackerData.order_id) { + var context = null; + if (window.clarioTrackerData.order_context) { + context = [{ + schema: "iglu:io.clar/transaction/jsonschema/1-0-0", + data: { + transaction: window.clarioTrackerData.order_context + } + }] + } + window.snowplow('addTrans', + window.clarioTrackerData.order_id, + window.clarioTrackerData.order_affiliation, + window.clarioTrackerData.order_total, + window.clarioTrackerData.order_tax || "", + window.clarioTrackerData.order_shipping || "", + "", + "", + "", + "", + context + ); - if (window.clarioTrackerData.order_id) { - var context = null; - if (window.clarioTrackerData.order_context) { - context = [{ - schema: "iglu:io.clar/transaction/jsonschema/1-0-0", - data: { - transaction: window.clarioTrackerData.order_context - } - }] - } - window.snowplow('addTrans', - window.clarioTrackerData.order_id, - window.clarioTrackerData.order_affiliation, - window.clarioTrackerData.order_total, - window.clarioTrackerData.order_tax || "", - window.clarioTrackerData.order_shipping || "", - "", - "", - "", - "", - context - ); - - if (window.clarioTrackerData.order_items) { - window.clarioTrackerData.order_items.forEach(function(item) { - window.snowplow('addItem', - item.orderId, - item.sku, - item.name, - "", - item.price, - item.quantity, - "", - item.context || "" - ); - }); - } + if (window.clarioTrackerData.order_items) { + window.clarioTrackerData.order_items.forEach(function (item) { + window.snowplow('addItem', + item.orderId, + item.sku, + item.name, + "", + item.price, + item.quantity, + "", + item.context || "" + ); + }); + } - window.snowplow('trackTrans'); + window.snowplow('trackTrans'); + } } - if (window.clarioTrackerData.gum_id) { - try { + var chewGum = function () { + if (window.clarioTrackerData.gum_id) { + try { - var collector = window.clarioTrackerData.collector || "c.clario.us"; - var gumUrl = "https://gum.criteo.com/sync?c=" + window.clarioTrackerData.gum_id + "&r=1&a=1&u="; + var collector = window.clarioTrackerData.collector || "c.clario.us"; + var gumUrl = "https://gum.criteo.com/sync?c=" + window.clarioTrackerData.gum_id + "&r=1&a=1&u="; - Object.keys(localStorage).forEach(function(key){ if (key.search(/_sp_id\.\w/) >= 0) - { - window.clarioTrackerData.sp_id = localStorage.getItem(key); + Object.keys(localStorage).forEach(function (key) { + if (key.search(/_sp_id\.\w/) >= 0) { + window.clarioTrackerData.sp_id = localStorage.getItem(key); + } + }); + + if (!window.clarioTrackerData.sp_id) { + window.clarioTrackerData.sp_id = document.cookie.split(";").find(function (cookie) { + return cookie.search(/_sp_id\..*=/) >= 0; + }).split("=")[1].split(".")[0]; } - }); - if (!window.clarioTrackerData.sp_id) { - window.clarioTrackerData.sp_id = document.cookie.split(";").find(function(cookie){return cookie.search(/_sp_id\..*=/) >= 0;}).split("=")[1].split(".")[0]; - } + var redirectUrl = + "https://" + + collector + + "/i?aid=" + + window.clarioTrackerData.app_id + + "&e=se&p=web&tv=2.10.2&se_ca=criteo&se_ac=cookie_match&se_la=" + + window.clarioTrackerData.sp_id || "" + + "&se_pr=@USERID@"; - var redirectUrl = - "https://" + - collector + - "/i?aid=" + - window.clarioTrackerData.app_id + - "&e=se&p=web&tv=2.10.2&se_ca=criteo&se_ac=cookie_match&se_la=" + - window.clarioTrackerData.sp_id || "" + - "&se_pr=@USERID@"; - - var xhr = new XMLHttpRequest(); - xhr.open('GET', gumUrl + encodeURIComponent(redirectUrl),true); - xhr.withCredentials = true; - xhr.send(); - } catch { - console.log("Error sending GUM request.") + var xhr = new XMLHttpRequest(); + xhr.open('GET', gumUrl + encodeURIComponent(redirectUrl), true); + xhr.withCredentials = true; + xhr.send(); + } catch { + console.log("Error sending GUM request.") + } } } -}()); + + trackIt() + orderUp() + chewGum() + + if (window.history) { + window.history.pushState = function (pushFn) { + return function pushState() { + var ret = pushFn.apply(this, arguments) + window.dispatchEvent(new Event("ClarioLocationChange")) + return ret + } + }(window.history.pushState) + + window.history.replaceState = function (replaceFn) { + return function replaceState() { + var ret = replaceFn.apply(this, arguments) + window.dispatchEvent(new Event("ClarioLocationChange")) + return ret + } + }(window.history.replaceState) + + // capture forward/backward navigation + window.addEventListener("popstate", function () { + window.dispatchEvent(new Event("ClarioLocationChange")) + }) + + window.addEventListener('ClarioLocationChange', function () { + trackIt() + orderUp() + chewGum() + }) + } +} +()); From 80001758e1f3a94842fe3427fefed575bcce9450 Mon Sep 17 00:00:00 2001 From: Dan Reiland Date: Mon, 30 Dec 2019 15:11:01 -0600 Subject: [PATCH 12/27] PNIX-2096 - Snowplow - Single Page Apps - Events Not Firing - Added find polyfill for IE - Made sp_id identification more robust --- src/js/clario.js | 90 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 70 insertions(+), 20 deletions(-) diff --git a/src/js/clario.js b/src/js/clario.js index fb4ad5301..e36f3f328 100644 --- a/src/js/clario.js +++ b/src/js/clario.js @@ -13,6 +13,53 @@ } }); + // Array.find polyfill for IE + if (!Array.prototype.find) { + Object.defineProperty(Array.prototype, 'find', { + value: function(predicate) { + // 1. Let O be ? ToObject(this value). + if (this == null) { + throw TypeError('"this" is null or not defined'); + } + + var o = Object(this); + + // 2. Let len be ? ToLength(? Get(O, "length")). + var len = o.length >>> 0; + + // 3. If IsCallable(predicate) is false, throw a TypeError exception. + if (typeof predicate !== 'function') { + throw TypeError('predicate must be a function'); + } + + // 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + var thisArg = arguments[1]; + + // 5. Let k be 0. + var k = 0; + + // 6. Repeat, while k < len + while (k < len) { + // a. Let Pk be ! ToString(k). + // b. Let kValue be ? Get(O, Pk). + // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + // d. If testResult is true, return kValue. + var kValue = o[k]; + if (predicate.call(thisArg, kValue, k, o)) { + return kValue; + } + // e. Increase k by 1. + k++; + } + + // 7. Return undefined. + return undefined; + }, + configurable: true, + writable: true + }); + } + var trackIt = function () { window.snowplow('setUserId', window.clarioTrackerData.customer_id); @@ -43,7 +90,7 @@ } else { window.snowplow('trackPageView'); } - } + }; var orderUp = function () { if (window.clarioTrackerData.order_id) { @@ -86,7 +133,7 @@ window.snowplow('trackTrans'); } - } + }; var chewGum = function () { if (window.clarioTrackerData.gum_id) { @@ -102,9 +149,13 @@ }); if (!window.clarioTrackerData.sp_id) { - window.clarioTrackerData.sp_id = document.cookie.split(";").find(function (cookie) { + var found = document.cookie.split(";").find(function (cookie) { return cookie.search(/_sp_id\..*=/) >= 0; - }).split("=")[1].split(".")[0]; + }); + + if (found) { + window.clarioTrackerData.sp_id = found.split("=")[1].split(".")[0]; + } } var redirectUrl = @@ -124,39 +175,38 @@ console.log("Error sending GUM request.") } } - } + }; - trackIt() - orderUp() - chewGum() + trackIt(); + orderUp(); + chewGum(); if (window.history) { window.history.pushState = function (pushFn) { return function pushState() { - var ret = pushFn.apply(this, arguments) - window.dispatchEvent(new Event("ClarioLocationChange")) + var ret = pushFn.apply(this, arguments); + window.dispatchEvent(new Event("ClarioLocationChange")); return ret } - }(window.history.pushState) + }(window.history.pushState); window.history.replaceState = function (replaceFn) { return function replaceState() { - var ret = replaceFn.apply(this, arguments) - window.dispatchEvent(new Event("ClarioLocationChange")) + var ret = replaceFn.apply(this, arguments); + window.dispatchEvent(new Event("ClarioLocationChange")); return ret } - }(window.history.replaceState) + }(window.history.replaceState); // capture forward/backward navigation window.addEventListener("popstate", function () { window.dispatchEvent(new Event("ClarioLocationChange")) - }) + }); window.addEventListener('ClarioLocationChange', function () { - trackIt() - orderUp() - chewGum() + trackIt(); + orderUp(); + chewGum(); }) } -} -()); +} ()); From c4ce128c1f98e1229c13c969453163b68cc105fe Mon Sep 17 00:00:00 2001 From: Dan Reiland Date: Mon, 30 Dec 2019 15:35:42 -0600 Subject: [PATCH 13/27] PNIX-2096 - Snowplow - Single Page Apps - Events Not Firing - Removed polyfill as it was causing issues (thanks, IE) - Added custom find function (thanks, loot) --- src/js/clario.js | 51 +++++------------------------------------------- 1 file changed, 5 insertions(+), 46 deletions(-) diff --git a/src/js/clario.js b/src/js/clario.js index e36f3f328..1be1d3483 100644 --- a/src/js/clario.js +++ b/src/js/clario.js @@ -13,51 +13,9 @@ } }); - // Array.find polyfill for IE - if (!Array.prototype.find) { - Object.defineProperty(Array.prototype, 'find', { - value: function(predicate) { - // 1. Let O be ? ToObject(this value). - if (this == null) { - throw TypeError('"this" is null or not defined'); - } - - var o = Object(this); - - // 2. Let len be ? ToLength(? Get(O, "length")). - var len = o.length >>> 0; - - // 3. If IsCallable(predicate) is false, throw a TypeError exception. - if (typeof predicate !== 'function') { - throw TypeError('predicate must be a function'); - } - // 4. If thisArg was supplied, let T be thisArg; else let T be undefined. - var thisArg = arguments[1]; - - // 5. Let k be 0. - var k = 0; - - // 6. Repeat, while k < len - while (k < len) { - // a. Let Pk be ! ToString(k). - // b. Let kValue be ? Get(O, Pk). - // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). - // d. If testResult is true, return kValue. - var kValue = o[k]; - if (predicate.call(thisArg, kValue, k, o)) { - return kValue; - } - // e. Increase k by 1. - k++; - } - - // 7. Return undefined. - return undefined; - }, - configurable: true, - writable: true - }); + function find(items, fn) { + return items.filter(fn)[0] } var trackIt = function () { @@ -66,7 +24,7 @@ var hits = []; var allTheCookies = document.cookie.split(";"); ["_fbp", "_ga"].forEach(function (term) { - var found = allTheCookies.find(function (cookie) { + var found = find(allTheCookies, function (cookie) { return cookie.indexOf(term + "=") >= 0; }); if (found) { @@ -149,7 +107,8 @@ }); if (!window.clarioTrackerData.sp_id) { - var found = document.cookie.split(";").find(function (cookie) { + var cookieAry = document.cookie.split(";"); + var found = find(cookieAry, function (cookie) { return cookie.search(/_sp_id\..*=/) >= 0; }); From 46159523039a26665081aeb4d7f738a4f76f137d Mon Sep 17 00:00:00 2001 From: Dan Reiland Date: Mon, 30 Dec 2019 15:45:20 -0600 Subject: [PATCH 14/27] PNIX-2096 - Snowplow - Single Page Apps - Events Not Firing - IE11 does not like dispatchEvent, so we just call plowIt() directly. --- src/js/clario.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/js/clario.js b/src/js/clario.js index 1be1d3483..c5a2427a5 100644 --- a/src/js/clario.js +++ b/src/js/clario.js @@ -136,15 +136,19 @@ } }; - trackIt(); - orderUp(); - chewGum(); + function plowIt () { + trackIt(); + orderUp(); + chewGum(); + } + + plowIt(); if (window.history) { window.history.pushState = function (pushFn) { return function pushState() { var ret = pushFn.apply(this, arguments); - window.dispatchEvent(new Event("ClarioLocationChange")); + plowIt(); return ret } }(window.history.pushState); @@ -152,20 +156,12 @@ window.history.replaceState = function (replaceFn) { return function replaceState() { var ret = replaceFn.apply(this, arguments); - window.dispatchEvent(new Event("ClarioLocationChange")); + plowIt(); return ret } }(window.history.replaceState); // capture forward/backward navigation - window.addEventListener("popstate", function () { - window.dispatchEvent(new Event("ClarioLocationChange")) - }); - - window.addEventListener('ClarioLocationChange', function () { - trackIt(); - orderUp(); - chewGum(); - }) + window.addEventListener("popstate", plowIt); } } ()); From b33c39b9e869e47c334a1803c7497b8bb73bfcc8 Mon Sep 17 00:00:00 2001 From: Dan Reiland Date: Thu, 2 Jan 2020 10:38:44 -0600 Subject: [PATCH 15/27] PNIX-2096 - Snowplow - Single Page Apps - Events Not Firing - Reverted window.history bits (FTD believes they have found the issue) --- src/js/clario.js | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/src/js/clario.js b/src/js/clario.js index c5a2427a5..b8f3a9c85 100644 --- a/src/js/clario.js +++ b/src/js/clario.js @@ -143,25 +143,4 @@ } plowIt(); - - if (window.history) { - window.history.pushState = function (pushFn) { - return function pushState() { - var ret = pushFn.apply(this, arguments); - plowIt(); - return ret - } - }(window.history.pushState); - - window.history.replaceState = function (replaceFn) { - return function replaceState() { - var ret = replaceFn.apply(this, arguments); - plowIt(); - return ret - } - }(window.history.replaceState); - - // capture forward/backward navigation - window.addEventListener("popstate", plowIt); - } } ()); From a4450c7958baf08fe3dc715f31038e7bb8cf7791 Mon Sep 17 00:00:00 2001 From: Dan Reiland Date: Mon, 13 Jan 2020 11:10:17 -0600 Subject: [PATCH 16/27] PNIX-2096 - Snowplow - Single Page Apps - Events Not Firing - Removed plowIt and related functions --- src/js/clario.js | 202 ++++++++++++++++++++++------------------------- 1 file changed, 94 insertions(+), 108 deletions(-) diff --git a/src/js/clario.js b/src/js/clario.js index b8f3a9c85..432607707 100644 --- a/src/js/clario.js +++ b/src/js/clario.js @@ -18,129 +18,115 @@ return items.filter(fn)[0] } - var trackIt = function () { - window.snowplow('setUserId', window.clarioTrackerData.customer_id); + window.snowplow('setUserId', window.clarioTrackerData.customer_id); - var hits = []; - var allTheCookies = document.cookie.split(";"); - ["_fbp", "_ga"].forEach(function (term) { - var found = find(allTheCookies, function (cookie) { - return cookie.indexOf(term + "=") >= 0; - }); - if (found) { - var parts = found.split("="); - if (parts.length == 2) { - hits.push({ - name: term, - value: parts[1] - }); - } - } + var hits = []; + var allTheCookies = document.cookie.split(";"); + ["_fbp", "_ga"].forEach(function (term) { + var found = find(allTheCookies, function (cookie) { + return cookie.indexOf(term + "=") >= 0; }); - - if (hits.length) { - window.snowplow('trackPageView', null, [{ - schema: "iglu:io.clar/cookies/jsonschema/2-0-0", - data: { - cookies: hits - } - }]); - } else { - window.snowplow('trackPageView'); - } - }; - - var orderUp = function () { - if (window.clarioTrackerData.order_id) { - var context = null; - if (window.clarioTrackerData.order_context) { - context = [{ - schema: "iglu:io.clar/transaction/jsonschema/1-0-0", - data: { - transaction: window.clarioTrackerData.order_context - } - }] + if (found) { + var parts = found.split("="); + if (parts.length == 2) { + hits.push({ + name: term, + value: parts[1] + }); } - window.snowplow('addTrans', - window.clarioTrackerData.order_id, - window.clarioTrackerData.order_affiliation, - window.clarioTrackerData.order_total, - window.clarioTrackerData.order_tax || "", - window.clarioTrackerData.order_shipping || "", - "", - "", - "", - "", - context - ); + } + }); - if (window.clarioTrackerData.order_items) { - window.clarioTrackerData.order_items.forEach(function (item) { - window.snowplow('addItem', - item.orderId, - item.sku, - item.name, - "", - item.price, - item.quantity, - "", - item.context || "" - ); - }); + if (hits.length) { + window.snowplow('trackPageView', null, [{ + schema: "iglu:io.clar/cookies/jsonschema/2-0-0", + data: { + cookies: hits } + }]); + } else { + window.snowplow('trackPageView'); + } - window.snowplow('trackTrans'); + if (window.clarioTrackerData.order_id) { + var context = null; + if (window.clarioTrackerData.order_context) { + context = [{ + schema: "iglu:io.clar/transaction/jsonschema/1-0-0", + data: { + transaction: window.clarioTrackerData.order_context + } + }] + } + window.snowplow('addTrans', + window.clarioTrackerData.order_id, + window.clarioTrackerData.order_affiliation, + window.clarioTrackerData.order_total, + window.clarioTrackerData.order_tax || "", + window.clarioTrackerData.order_shipping || "", + "", + "", + "", + "", + context + ); + + if (window.clarioTrackerData.order_items) { + window.clarioTrackerData.order_items.forEach(function (item) { + window.snowplow('addItem', + item.orderId, + item.sku, + item.name, + "", + item.price, + item.quantity, + "", + item.context || "" + ); + }); } - }; - - var chewGum = function () { - if (window.clarioTrackerData.gum_id) { - try { - var collector = window.clarioTrackerData.collector || "c.clario.us"; - var gumUrl = "https://gum.criteo.com/sync?c=" + window.clarioTrackerData.gum_id + "&r=1&a=1&u="; + window.snowplow('trackTrans'); + } - Object.keys(localStorage).forEach(function (key) { - if (key.search(/_sp_id\.\w/) >= 0) { - window.clarioTrackerData.sp_id = localStorage.getItem(key); - } - }); + if (window.clarioTrackerData.gum_id) { + try { - if (!window.clarioTrackerData.sp_id) { - var cookieAry = document.cookie.split(";"); - var found = find(cookieAry, function (cookie) { - return cookie.search(/_sp_id\..*=/) >= 0; - }); + var collector = window.clarioTrackerData.collector || "c.clario.us"; + var gumUrl = "https://gum.criteo.com/sync?c=" + window.clarioTrackerData.gum_id + "&r=1&a=1&u="; - if (found) { - window.clarioTrackerData.sp_id = found.split("=")[1].split(".")[0]; - } + Object.keys(localStorage).forEach(function (key) { + if (key.search(/_sp_id\.\w/) >= 0) { + window.clarioTrackerData.sp_id = localStorage.getItem(key); } + }); - var redirectUrl = - "https://" + - collector + - "/i?aid=" + - window.clarioTrackerData.app_id + - "&e=se&p=web&tv=2.10.2&se_ca=criteo&se_ac=cookie_match&se_la=" + - window.clarioTrackerData.sp_id || "" + - "&se_pr=@USERID@"; + if (!window.clarioTrackerData.sp_id) { + var cookieAry = document.cookie.split(";"); + var found = find(cookieAry, function (cookie) { + return cookie.search(/_sp_id\..*=/) >= 0; + }); - var xhr = new XMLHttpRequest(); - xhr.open('GET', gumUrl + encodeURIComponent(redirectUrl), true); - xhr.withCredentials = true; - xhr.send(); - } catch { - console.log("Error sending GUM request.") + if (found) { + window.clarioTrackerData.sp_id = found.split("=")[1].split(".")[0]; + } } - } - }; - function plowIt () { - trackIt(); - orderUp(); - chewGum(); + var redirectUrl = + "https://" + + collector + + "/i?aid=" + + window.clarioTrackerData.app_id + + "&e=se&p=web&tv=2.10.2&se_ca=criteo&se_ac=cookie_match&se_la=" + + window.clarioTrackerData.sp_id || "" + + "&se_pr=@USERID@"; + + var xhr = new XMLHttpRequest(); + xhr.open('GET', gumUrl + encodeURIComponent(redirectUrl), true); + xhr.withCredentials = true; + xhr.send(); + } catch { + console.log("Error sending GUM request.") + } } - - plowIt(); } ()); From 7ea62ff8898e31000d9061ada14d32f2bb3596db Mon Sep 17 00:00:00 2001 From: Dan Reiland Date: Wed, 17 Jun 2020 16:55:56 -0500 Subject: [PATCH 17/27] PNIX-2272 Snowplow - Add page_meta context - refactored to allow contexts to be added to trackPageView calls as needed - added page_meta context --- src/js/clario.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/js/clario.js b/src/js/clario.js index 432607707..524a1b08e 100644 --- a/src/js/clario.js +++ b/src/js/clario.js @@ -20,7 +20,8 @@ window.snowplow('setUserId', window.clarioTrackerData.customer_id); - var hits = []; + var contexts = []; + var cookies = []; var allTheCookies = document.cookie.split(";"); ["_fbp", "_ga"].forEach(function (term) { var found = find(allTheCookies, function (cookie) { @@ -29,7 +30,7 @@ if (found) { var parts = found.split("="); if (parts.length == 2) { - hits.push({ + cookies.push({ name: term, value: parts[1] }); @@ -37,13 +38,26 @@ } }); - if (hits.length) { - window.snowplow('trackPageView', null, [{ + if (cookies.length) { + contexts.push({ schema: "iglu:io.clar/cookies/jsonschema/2-0-0", data: { - cookies: hits + cookies: cookies } - }]); + }); + } + + if (window.clarioTrackerData.page_meta && window.clarioTrackerData.page_meta.length) { + contexts.push({ + schema: "iglu:io.clar/page_meta/jsonschema/1-0-0", + data: { + page_meta: window.clarioTrackerData.page_meta + } + }); + } + + if (contexts.length) { + window.snowplow('trackPageView', null, contexts); } else { window.snowplow('trackPageView'); } From b0ad4813410febd982b3f35d229c06438b4d5c21 Mon Sep 17 00:00:00 2001 From: loot Date: Tue, 28 Jul 2020 11:47:39 -0500 Subject: [PATCH 18/27] Fixing inability to chew gum --- src/js/clario.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/clario.js b/src/js/clario.js index 524a1b08e..9ad795a45 100644 --- a/src/js/clario.js +++ b/src/js/clario.js @@ -132,7 +132,7 @@ "/i?aid=" + window.clarioTrackerData.app_id + "&e=se&p=web&tv=2.10.2&se_ca=criteo&se_ac=cookie_match&se_la=" + - window.clarioTrackerData.sp_id || "" + + (window.clarioTrackerData.sp_id || "") + "&se_pr=@USERID@"; var xhr = new XMLHttpRequest(); From f46fc2a5b7344edadb7579de6493c45fdd09f001 Mon Sep 17 00:00:00 2001 From: Chris Alme Date: Tue, 28 Jul 2020 14:57:57 -0500 Subject: [PATCH 19/27] PNIX-2013 - Snowplow - Tag - CBK - Enable Criteo GUM tracker Fixed the issue, just using this ticket to check in against. Now w/ 1P cookies, first look for sp cookie (set by collector) to pass to GUM. If 1P not found, fall back to local storage (need to parse the returned value just like the cookie). --- src/js/clario.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/js/clario.js b/src/js/clario.js index 9ad795a45..dd8ee2bfa 100644 --- a/src/js/clario.js +++ b/src/js/clario.js @@ -109,21 +109,20 @@ var collector = window.clarioTrackerData.collector || "c.clario.us"; var gumUrl = "https://gum.criteo.com/sync?c=" + window.clarioTrackerData.gum_id + "&r=1&a=1&u="; - Object.keys(localStorage).forEach(function (key) { - if (key.search(/_sp_id\.\w/) >= 0) { - window.clarioTrackerData.sp_id = localStorage.getItem(key); - } + var found = find(document.cookie.split(";"), function (cookie) { + return cookie.search(/sp=/) >= 0; }); + if (found) { + window.clarioTrackerData.sp_id = found.split("=")[1].split(".")[0]; + } + if (!window.clarioTrackerData.sp_id) { - var cookieAry = document.cookie.split(";"); - var found = find(cookieAry, function (cookie) { - return cookie.search(/_sp_id\..*=/) >= 0; + Object.keys(localStorage).forEach(function (key) { + if (key.search(/_sp_id\.\w*$/) >= 0) { + window.clarioTrackerData.sp_id = localStorage.getItem(key).split(".")[0]; + } }); - - if (found) { - window.clarioTrackerData.sp_id = found.split("=")[1].split(".")[0]; - } } var redirectUrl = From f88cdb01c6003c1ce2b6aa5b3aa7cfb1942db5cf Mon Sep 17 00:00:00 2001 From: Chris Alme Date: Wed, 29 Jul 2020 08:15:45 -0500 Subject: [PATCH 20/27] PNIX-2013 - Snowplow - Tag - CBK - Enable Criteo GUM tracker Added some comments to document the change in logic for which "ID" we pass to Criteo. --- src/js/clario.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/js/clario.js b/src/js/clario.js index dd8ee2bfa..e798f6171 100644 --- a/src/js/clario.js +++ b/src/js/clario.js @@ -109,6 +109,7 @@ var collector = window.clarioTrackerData.collector || "c.clario.us"; var gumUrl = "https://gum.criteo.com/sync?c=" + window.clarioTrackerData.gum_id + "&r=1&a=1&u="; + // First check our newly minted 1P collector cookie (appears in network_userid) var found = find(document.cookie.split(";"), function (cookie) { return cookie.search(/sp=/) >= 0; }); @@ -117,6 +118,7 @@ window.clarioTrackerData.sp_id = found.split("=")[1].split(".")[0]; } + // If 1P collector cookie is missing, fall back to the 1P ID in local storage (appears in domain_userid) if (!window.clarioTrackerData.sp_id) { Object.keys(localStorage).forEach(function (key) { if (key.search(/_sp_id\.\w*$/) >= 0) { From 9d69b8f724b7ed68d8c0d1f0e55f773e63de6b36 Mon Sep 17 00:00:00 2001 From: Dan Reiland Date: Tue, 18 Aug 2020 12:46:39 -0500 Subject: [PATCH 21/27] PNIX-2314 Snowplow - Enable Activity Tracking - enabled activity tracking --- src/js/clario.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/js/clario.js b/src/js/clario.js index e798f6171..2a7e44b78 100644 --- a/src/js/clario.js +++ b/src/js/clario.js @@ -56,6 +56,7 @@ }); } + window.snowplow('enableActivityTracking', 10, 10); if (contexts.length) { window.snowplow('trackPageView', null, contexts); } else { From 614b063c11bb5c3484b272caf858fadf7e676d30 Mon Sep 17 00:00:00 2001 From: Dan Reiland Date: Wed, 7 Oct 2020 08:12:05 -0500 Subject: [PATCH 22/27] PNIX-2357 Plowio - Upgrade to Snowplow JavaScript Tracker v2.16.1 - Commented out "Tracker namespace already exists" warning as it causes issues for our clients that run site exception monitoring - Updated require to import --- src/js/in_queue.js | 2 +- src/js/init.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/in_queue.js b/src/js/in_queue.js index 70a8110cb..b2be622d7 100644 --- a/src/js/in_queue.js +++ b/src/js/in_queue.js @@ -110,7 +110,7 @@ export function InQueueManager(TrackerConstructor, version, mutSnowplowState, as trackerDictionary[namespace] = new TrackerConstructor(functionName, namespace, version, mutSnowplowState, argmap); trackerDictionary[namespace].setCollectorUrl(endpoint); } else { - warn('Tracker namespace ' + namespace + ' already exists.'); + //warn('Tracker namespace ' + namespace + ' already exists.'); } } diff --git a/src/js/init.js b/src/js/init.js index f268436e5..48255913c 100644 --- a/src/js/init.js +++ b/src/js/init.js @@ -39,7 +39,7 @@ */ // Inject Clario stuff first -require('./clario'); +import './clario'; import { Snowplow } from './snowplow'; From 27fe059d5e3d44d3e2508686037de40638abf4e5 Mon Sep 17 00:00:00 2001 From: Dan Reiland Date: Thu, 8 Oct 2020 11:35:17 -0500 Subject: [PATCH 23/27] PNIX-2357 Plowio - Upgrade to Snowplow JavaScript Tracker v2.16.1 - Created two variants of init.js (plowio and vanilla) to facilitate targeting via the build - Removed github actions and templates --- .github/ISSUE_TEMPLATE/bug_report.md | 34 -------- .github/ISSUE_TEMPLATE/feature_request.md | 20 ----- .github/workflows/build.yml | 76 ---------------- .github/workflows/deploy_core.yml | 56 ------------ .github/workflows/deploy_tracker.yml | 101 ---------------------- .github/workflows/snyk.yml | 28 ------ src/js/{init.js => init-plowio.js} | 2 +- src/js/init-vanilla.js | 54 ++++++++++++ 8 files changed, 55 insertions(+), 316 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/bug_report.md delete mode 100644 .github/ISSUE_TEMPLATE/feature_request.md delete mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/deploy_core.yml delete mode 100644 .github/workflows/deploy_tracker.yml delete mode 100644 .github/workflows/snyk.yml rename src/js/{init.js => init-plowio.js} (97%) create mode 100644 src/js/init-vanilla.js diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index 60eb9392b..000000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,34 +0,0 @@ ---- -name: Bug report -about: Create a report to help us improve -title: '' -labels: type:defect -assignees: '' - ---- - -**Describe the bug** -A clear and concise description of what the bug is. - -**To Reproduce** -Steps to reproduce the behavior or code snippets that produce the issue. - -**Expected behavior** -A clear and concise description of what you expected to happen. - -**Screenshots** -If applicable, add screenshots to help explain your problem. - -**Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - Version [e.g. 22] - -**Smartphone (please complete the following information):** - - Device: [e.g. iPhone6] - - OS: [e.g. iOS8.1] - - Browser [e.g. stock browser, safari] - - Version [e.g. 22] - -**Additional context** -Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index 36db55952..000000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -name: Feature request -about: Suggest an idea for this project -title: '' -labels: type:enhancement -assignees: '' - ---- - -**Is your feature request related to a problem? Please describe.** -A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] - -**Describe the solution you'd like** -A clear and concise description of what you want to happen. - -**Describe alternatives you've considered** -A clear and concise description of any alternative solutions or features you've considered. - -**Additional context** -Add any other context or screenshots about the feature request here. diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 59bd2f7f7..000000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,76 +0,0 @@ -name: Build - -on: - push: - branches: - - '**' # Prevents builds on tag - pull_request: - -jobs: - build: - runs-on: ubuntu-latest - - env: - SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }} - SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }} - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Use Node.js 12 - uses: actions/setup-node@v1 - with: - node-version: 12.x - - - name: npm cache - uses: actions/cache@v2 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: ${{ runner.os }}-node- - - - name: Core npm ci - working-directory: ./core - run: npm ci - - - name: Build core - working-directory: ./core - run: npm run build - - - name: Test core - working-directory: ./core - run: npm run test - - - name: Tracker npm ci - run: npm ci - - - name: Build tracker - run: npm run build - - - name: Test tracker - run: npm run test:unit - - - name: Block Concurrent Executions of E2E Tests - if: ${{ env.SAUCE_ACCESS_KEY != '' }} - uses: softprops/turnstyle@v1 - with: - poll-interval-seconds: 10 - same-branch-only: false - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Add Host for Saucelabs Tunnel - if: ${{ env.SAUCE_ACCESS_KEY != '' }} - run: echo "127.0.0.1 snowplow-js-tracker.local" | sudo tee -a /etc/hosts - - - name: Run End to End Tests - run: npm run test:e2e:sauce - if: ${{ env.SAUCE_ACCESS_KEY != '' }} - - - name: Upload sp.js artifact - uses: actions/upload-artifact@v2 - with: - name: sp.js - path: dist/sp.js - diff --git a/.github/workflows/deploy_core.yml b/.github/workflows/deploy_core.yml deleted file mode 100644 index 73b9467f3..000000000 --- a/.github/workflows/deploy_core.yml +++ /dev/null @@ -1,56 +0,0 @@ -name: Deploy Core - -on: - push: - tags: - - 'core/*.*.*' - -jobs: - deploy: - runs-on: ubuntu-latest - - defaults: - run: - working-directory: core - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Use Node.js 12 - uses: actions/setup-node@v1 - with: - node-version: 12 - registry-url: https://registry.npmjs.org/ - - - name: npm cache - uses: actions/cache@v2 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: ${{ runner.os }}-node- - - - run: npm ci - - - name: Build core - run: npm run build - - - name: Test core - run: npm run test - - - name: Get tag and tracker version information - id: version - run: | - echo ::set-output name=TAG_VERSION::${GITHUB_REF#refs/*/} - echo "##[set-output name=TRACKER_VERSION;]$(node -p "require('./package.json').version")" - - - name: Fail if version mismatch - if: ${{ steps.version.outputs.TAG_VERSION != format('core/{0}', steps.version.outputs.TRACKER_VERSION) }} - run: | - echo "Tag version (${{ steps.version.outputs.TAG_VERSION }}) doesn't match version in project (${{ format('core/{0}', steps.version.outputs.TRACKER_VERSION) }})" - exit 1 - - - name: Publish - run: npm publish - env: - NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} diff --git a/.github/workflows/deploy_tracker.yml b/.github/workflows/deploy_tracker.yml deleted file mode 100644 index d177bf215..000000000 --- a/.github/workflows/deploy_tracker.yml +++ /dev/null @@ -1,101 +0,0 @@ -name: Deploy Tracker - -on: - push: - tags: - - '*.*.*' - -jobs: - deploy: - runs-on: ubuntu-latest - - env: - SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }} - SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }} - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Use Node.js 12 - uses: actions/setup-node@v1 - with: - node-version: 12 - - - name: npm cache - uses: actions/cache@v2 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: ${{ runner.os }}-node- - - - name: Core npm ci - working-directory: ./core - run: npm ci - - - name: Build core - working-directory: ./core - run: npm run build - - - name: Test core - working-directory: ./core - run: npm run test - - - name: Tracker npm ci - run: npm ci - - - name: Build tracker - run: npm run build - - - name: Test tracker - run: npm run test:unit - - - name: Block Concurrent Executions of E2E Tests - if: ${{ env.SAUCE_ACCESS_KEY != '' }} - uses: softprops/turnstyle@v1 - with: - poll-interval-seconds: 10 - same-branch-only: false - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Add Host for Saucelabs Tunnel - if: ${{ env.SAUCE_ACCESS_KEY != '' }} - run: echo "127.0.0.1 snowplow-js-tracker.local" | sudo tee -a /etc/hosts - - - name: Run End to End Tests - run: npm run test:e2e:sauce - if: ${{ env.SAUCE_ACCESS_KEY != '' }} - - - name: Get tag and tracker version information - id: version - run: | - echo ::set-output name=TAG_VERSION::${GITHUB_REF#refs/*/} - echo "##[set-output name=TRACKER_VERSION;]$(node -p "require('./package.json').version")" - - - name: Fail if version mismatch - if: ${{ steps.version.outputs.TAG_VERSION != steps.version.outputs.TRACKER_VERSION }} - run: | - echo "Tag version (${{ steps.version.outputs.TAG_VERSION }}) doesn't match version in project (${{ steps.version.outputs.TRACKER_VERSION }})" - exit 1 - - - name: Create release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ github.ref }} - release_name: Snowplow JavaScript Tracker v${{ github.ref }} - draft: false - prerelease: ${{ contains(steps.version.outputs.TAG_VERSION, '-M') }} - - - name: Upload sp.js asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./dist/sp.js - asset_name: sp.js - asset_content_type: application/javascript diff --git a/.github/workflows/snyk.yml b/.github/workflows/snyk.yml deleted file mode 100644 index c4435edfc..000000000 --- a/.github/workflows/snyk.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Snyk -on: - push: - branches: [ master ] -jobs: - security: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Use Node.js 12 - uses: actions/setup-node@v1 - with: - node-version: 12 - - - name: Run npm install on Core - run: npm ci - working-directory: ./core - - - name: Run npm intall on Tracker - run: npm ci - - - name: Run Snyk to check for vulnerabilities - uses: snyk/actions/node@master - with: - command: monitor - args: --all-projects - env: - SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} diff --git a/src/js/init.js b/src/js/init-plowio.js similarity index 97% rename from src/js/init.js rename to src/js/init-plowio.js index 48255913c..4fec43bce 100644 --- a/src/js/init.js +++ b/src/js/init-plowio.js @@ -1,5 +1,5 @@ /* - * JavaScript tracker for Snowplow: init.js + * JavaScript tracker for Snowplow: init-plowio.js * * Significant portions copyright 2010 Anthon Pang. Remainder copyright * 2012-2020 Snowplow Analytics Ltd. All rights reserved. diff --git a/src/js/init-vanilla.js b/src/js/init-vanilla.js new file mode 100644 index 000000000..f4e124f9d --- /dev/null +++ b/src/js/init-vanilla.js @@ -0,0 +1,54 @@ +/* + * JavaScript tracker for Snowplow: init-plowio.js + * + * Significant portions copyright 2010 Anthon Pang. Remainder copyright + * 2012-2020 Snowplow Analytics Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Anthon Pang nor Snowplow Analytics Ltd nor the + * names of their contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// Snowplow Asynchronous Queue + +/* + * Get the name of the global input function + */ + +import { Snowplow } from './snowplow'; + +var queueName, + queue, + windowAlias = window; + +if (windowAlias.GlobalSnowplowNamespace && windowAlias.GlobalSnowplowNamespace.length > 0) { + queueName = windowAlias.GlobalSnowplowNamespace.shift(); + queue = windowAlias[queueName]; + queue.q = new Snowplow(queue.q, queueName); +} else { + windowAlias._snaq = windowAlias._snaq || []; + windowAlias._snaq = new Snowplow(windowAlias._snaq, '_snaq'); +} From 5b05c3348c2f8e4c13c772b948d7381b0af6f24e Mon Sep 17 00:00:00 2001 From: Dan Reiland Date: Thu, 8 Oct 2020 12:03:22 -0500 Subject: [PATCH 24/27] PNIX-2357 Plowio - Upgrade to Snowplow JavaScript Tracker v2.16.1 - The file name should remain init.js --- src/js/{init-plowio.js => init.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/js/{init-plowio.js => init.js} (100%) diff --git a/src/js/init-plowio.js b/src/js/init.js similarity index 100% rename from src/js/init-plowio.js rename to src/js/init.js From cdf40a7d9b697a4e68bb984cc89c584f480a7387 Mon Sep 17 00:00:00 2001 From: Dan Reiland Date: Wed, 7 Sep 2022 15:48:06 -0500 Subject: [PATCH 25/27] PNIX-3561 Snowplow - Page Ping Deactivation - ECK - Removed activity tracking --- src/js/clario.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/js/clario.js b/src/js/clario.js index 2a7e44b78..e798f6171 100644 --- a/src/js/clario.js +++ b/src/js/clario.js @@ -56,7 +56,6 @@ }); } - window.snowplow('enableActivityTracking', 10, 10); if (contexts.length) { window.snowplow('trackPageView', null, contexts); } else { From 33d9c6f957b0582f17619eaba32bca7e37e79ca4 Mon Sep 17 00:00:00 2001 From: Dan Reiland Date: Wed, 11 Jan 2023 10:18:55 -0600 Subject: [PATCH 26/27] PNIX-3561 Snowplow - Page Ping Deactivation - ECK - trying to get the build running under docker --- core/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/Dockerfile b/core/Dockerfile index 6ccc9b35c..bc5317e82 100644 --- a/core/Dockerfile +++ b/core/Dockerfile @@ -15,6 +15,7 @@ FROM node:erbium-alpine WORKDIR /code COPY package*.json ./ -RUN npm install +RUN npm install; npm install --global gulp-cli + COPY . . From 37e56a40bc664012028ad4057517cc3bba031f2d Mon Sep 17 00:00:00 2001 From: Dan Reiland Date: Wed, 11 Jan 2023 10:20:08 -0600 Subject: [PATCH 27/27] Revert "PNIX-3561 Snowplow - Page Ping Deactivation - ECK - trying to get the build running under docker" This reverts commit 33d9c6f957b0582f17619eaba32bca7e37e79ca4. --- core/Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/Dockerfile b/core/Dockerfile index bc5317e82..6ccc9b35c 100644 --- a/core/Dockerfile +++ b/core/Dockerfile @@ -15,7 +15,6 @@ FROM node:erbium-alpine WORKDIR /code COPY package*.json ./ -RUN npm install; npm install --global gulp-cli - +RUN npm install COPY . .