From b67023f8f5d8337e45cb932f23068771dee7d2b1 Mon Sep 17 00:00:00 2001 From: jdboix Date: Wed, 14 Aug 2019 16:56:49 -0500 Subject: [PATCH] Make path configurable --- src/js/out_queue.js | 55 +++++++++++++++++++++++---------------------- src/js/tracker.js | 21 ++++++++++------- 2 files changed, 41 insertions(+), 35 deletions(-) diff --git a/src/js/out_queue.js b/src/js/out_queue.js index ee383d9cb..97714e19f 100644 --- a/src/js/out_queue.js +++ b/src/js/out_queue.js @@ -1,34 +1,34 @@ /* * JavaScript tracker for Snowplow: out_queue.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. */ @@ -53,6 +53,7 @@ * @param boolean useLocalStorage Whether to use localStorage at all * @param string eventMethod if null will use 'beacon' otherwise can be set to 'post', 'get', or 'beacon' to force. * @param string postPath The path where events are to be posted + * @param string customPath Custom path where events are to be sent * @param int bufferSize How many events to batch in localStorage before sending them all. * Only applies when sending POST requests and when localStorage is available. * @param int maxPostBytes Maximum combined size in bytes of the event JSONs in a POST request @@ -60,15 +61,15 @@ * * @return object OutQueueManager instance */ - object.OutQueueManager = function (functionName, namespace, mutSnowplowState, useLocalStorage, eventMethod, postPath, bufferSize, maxPostBytes, useStm) { + object.OutQueueManager = function (functionName, namespace, mutSnowplowState, useLocalStorage, eventMethod, postPath, customPath, bufferSize, maxPostBytes, useStm) { var queueName, executingQueue = false, configCollectorUrl, outQueue; - + //Force to lower case if its a string eventMethod = eventMethod.toLowerCase ? eventMethod.toLowerCase() : eventMethod; - + // Use the Beacon API if eventMethod is set null, true, or 'beacon'. var isBeaconRequested = (eventMethod === null) || (eventMethod === true) || (eventMethod === "beacon") || (eventMethod === "true"); // Fall back to POST or GET for browsers which don't support Beacon API @@ -86,7 +87,7 @@ usePost = usePost && Boolean(window.XMLHttpRequest && ('withCredentials' in new XMLHttpRequest())); // Resolve all options and capabilities and decide path - var path = usePost ? postPath : '/i'; + var path = customPath ? customPath : (usePost ? postPath : 'i'); bufferSize = (localStorageAccessible() && useLocalStorage && usePost && bufferSize) || 1; diff --git a/src/js/tracker.js b/src/js/tracker.js index d00cd4a07..7db940f08 100755 --- a/src/js/tracker.js +++ b/src/js/tracker.js @@ -79,13 +79,14 @@ * 15. eventMethod, 'post' * 16. post, false *DEPRECATED use eventMethod instead* * 17. postPath, null - * 18. useStm, true - * 19. bufferSize, 1 - * 20. crossDomainLinker, false - * 21. maxPostBytes, 40000 - * 22. discoverRootDomain, false - * 23. cookieLifetime, 63072000 - * 24. stateStorageStrategy, 'cookieAndLocalStorage' + * 18. customPath, null + * 19. useStm, true + * 20. bufferSize, 1 + * 21. crossDomainLinker, false + * 22. maxPostBytes, 40000 + * 23. discoverRootDomain, false + * 24. cookieLifetime, 63072000 + * 25. stateStorageStrategy, 'cookieAndLocalStorage' */ object.Tracker = function Tracker(functionName, namespace, version, mutSnowplowState, argmap) { @@ -156,6 +157,9 @@ // Custom path for post requests (to get around adblockers) configPostPath = argmap.hasOwnProperty('postPath') ? argmap.postPath : '/com.snowplowanalytics.snowplow/tp2', + // Custom path for sending events + configCustomPath = argmap.hasOwnProperty('customPath') ? argmap.customPath : null, + // Site ID configTrackerSiteId = argmap.hasOwnProperty('appId') ? argmap.appId : '', // Updated for Snowplow @@ -317,6 +321,7 @@ configStateStorageStrategy == 'cookieAndLocalStorage', argmap.eventMethod, configPostPath, + configCustomPath, argmap.bufferSize, argmap.maxPostBytes || 40000, argmap.useStm), @@ -450,7 +455,7 @@ if (configDiscardBrace) { targetPattern = new RegExp('[{}]', 'g'); - url = url.replace(targetPattern, ''); + url = url.replace(targetPattern, ''); } return url; }