Skip to content

Commit 233eb05

Browse files
author
Scotty Jacobson
committed
iOS workaround: send a POST XHR request before _every_ sendBeacon call
this is more heavy-handed than we'd like and will pollute our bad-events stream; i'll tweak and find the exact times i need to make this request
1 parent c43a70f commit 233eb05

3 files changed

Lines changed: 3 additions & 3 deletions

File tree

src/js/lib/beacon_ios_workaround.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
// https://robertsahlin.com/analytics-beacon-transport-mechanism-gotchas/
6767
// https://bugs.webkit.org/show_bug.cgi?id=193508
6868
var xhr = new XMLHttpRequest();
69-
xhr.open('POST', collectorUrl + '/com.snowplowanalytics/tp2', true);
69+
xhr.open('POST', collectorUrl, true);
7070
xhr.setRequestHeader('Content-Type', 'text/plain');
7171
xhr.withCredentials = true;
7272
xhr.send('unlockBeacon');

src/js/out_queue.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
isString = require('lodash/isString'),
4040
map = require('lodash/map'),
4141
localStorageAccessible = require('./lib/detectors').localStorageAccessible,
42+
beaconiOSWorkaround = require('./lib/beacon_ios_workaround'),
4243
helpers = require('./lib/helpers'),
4344
object = typeof exports !== 'undefined' ? exports : this; // For eventual node.js environment support
4445

@@ -314,6 +315,7 @@
314315
}
315316
const blob = new Blob([encloseInPayloadDataEnvelope(attachStmToEvent(batch))], headers);
316317
try {
318+
beaconiOSWorkaround.unlockBeacon(configCollectorUrl);
317319
beaconStatus = navigator.sendBeacon(configCollectorUrl, blob);
318320
}
319321
catch(error) {

src/js/tracker.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
links = require('./links'),
4646
forms = require('./forms'),
4747
errors = require('./errors'),
48-
beaconiOSWorkaround = require('./lib/beacon_ios_workaround'),
4948
requestQueue = require('./out_queue'),
5049
coreConstructor = require('snowplow-tracker-core').trackerCore,
5150
productionize = require('./guard').productionize,
@@ -2139,7 +2138,6 @@
21392138
*/
21402139
apiMethods.setCollectorUrl = function (rawUrl) {
21412140
configCollectorUrl = asCollectorUrl(rawUrl);
2142-
beaconiOSWorkaround.unlockBeacon(configCollectorUrl);
21432141
};
21442142

21452143
/**

0 commit comments

Comments
 (0)