Skip to content

Instantly share code, notes, and snippets.

Created Nov 13, 2017
What would you like to do?
Extract a url parameter and pass it into a tracking pixel url
// This script extracts a url parameter (transactionId) and passes it into a tracking pixel url (trackingPixelUrl)
// It is designed to be added to a squarespace custom js block
// References:
window.onload = function() {
// Create a function that fetches a given argument from the url
function fetchUrlArgument(argumentName) {
// Build array of url arguments
queryString =;
arguments = queryString.split("&");
// Loop through all the arguments
for (i = 0; i < arguments.length; i++) {
// Split each argument (key=value) on the equals sign
argument = arguments[i].split("=");
// Check if the key matches the argument we're looking for
if (argument[0] == argumentName) {
// If it does then return the value
return argument[1];
// Call the function for the argument we want to fetch
var transactionId = fetchUrlArgument("transactionId");
// If the argument is found then display our tracking pixel
if (transactionId) {
// Setup the tracking pixel
trackingPixelUrl = ''
trackingPixel = '<iframe src="' + trackingPixelUrl + transactionId + '" height="1" width="1" frameborder="0"></iframe>';
// Find the tracking pixel placeholder
trackingPixelPlaceholder = document.getElementById("trackingPixelPlaceholder");
// If the placeholder exists then inject the tracking pixel
if (trackingPixelPlaceholder) {
trackingPixelPlaceholder.innerHTML = trackingPixel;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment