Testing image beacons

JavaScript tracker related question:
How are image beacons (new Image().src = ‘collectur-url/…’) tested?
I am developing a tracker in JavaScript using Snowplow’s JS tracker, but having difficulties with testing SP’s functionality.
A bit more in detail: it’s hard to detect if an image beacon is being processed or it’s done loading because it is not appended anywhere on the page. Right now I only rely on timing of requests, meaning after I track an event using SP tracker I have to wait few hundred milliseconds to start testing against my test cases.
We were thinking about leveraging the localStorage capabilities when the collector is not reachable (and basically events are persisted for later usage) - so we could test against the values of the localStorage, but this is not really testing the actual workflow.
Do you have any suggestions?
Thanks,
Adam

1 Like

Generally if you are testing you’ll want to test by intercepting the network request. These network requests to the collector should happen immediately in the Javascript tracker unless you are using POST requests with buffer settings.

You can find the logic for enqueuing the requests (before sending) here.

Hey Mike, thanks for your answer!
So does that mean that the current setup for https://github.com/snowplow/snowplow-javascript-tracker is using network interceptors for testing Image beacons?