Skip to content

Commit c3b5938

Browse files
jaredsilvermhadam
authored andcommitted
Add option to set a custom POST request path (close #696)
1 parent 89ed2d7 commit c3b5938

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/js/out_queue.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@
5353
* @param int bufferSize How many events to batch in localStorage before sending them all.
5454
* Only applies when sending POST requests and when localStorage is available.
5555
* @param int maxPostBytes Maximum combined size in bytes of the event JSONs in a POST request
56+
* @param string postPath The path where events are to be posted
5657
* @return object OutQueueManager instance
5758
*/
58-
object.OutQueueManager = function (functionName, namespace, mutSnowplowState, useLocalStorage, usePost, bufferSize, maxPostBytes) {
59+
object.OutQueueManager = function (functionName, namespace, mutSnowplowState, useLocalStorage, usePost, postPath, bufferSize, maxPostBytes) {
5960
var queueName,
6061
executingQueue = false,
6162
configCollectorUrl,
@@ -64,7 +65,7 @@
6465
// Fall back to GET for browsers which don't support CORS XMLHttpRequests (e.g. IE <= 9)
6566
usePost = usePost && window.XMLHttpRequest && ('withCredentials' in new XMLHttpRequest());
6667

67-
var path = usePost ? '/com.snowplowanalytics.snowplow/tp2' : '/i';
68+
var path = usePost ? postPath : '/i';
6869

6970
bufferSize = (localStorageAccessible() && useLocalStorage && usePost && bufferSize) || 1;
7071

src/js/tracker.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@
121121
// Snowplow collector URL
122122
configCollectorUrl,
123123

124+
// Custom path for post requests (to get around adblockers)
125+
configPostPath = argmap.hasOwnProperty('postPath') ? argmap.postPath : '/com.snowplowanalytics.snowplow/tp2',
126+
124127
// Site ID
125128
configTrackerSiteId = argmap.hasOwnProperty('appId') ? argmap.appId : '', // Updated for Snowplow
126129

@@ -278,6 +281,7 @@
278281
configStateStorageStrategy == 'localStorage' ||
279282
configStateStorageStrategy == 'cookieAndLocalStorage',
280283
argmap.post,
284+
configPostPath,
281285
argmap.bufferSize,
282286
argmap.maxPostBytes || 40000),
283287

0 commit comments

Comments
 (0)