OP Custom Tag - Organizing Query Parameters per Page
Overview
- Test for the presence of required parameters (e.g. cid)
- Test for the correct name conventions and taxonomy of your campaigns, as they are intended in your query parameters (e.g. use regex in a Rule to enforce naming conventions)
- Test for the presence of typos or identifiable errors that may affect your attribution and campaign measurement
function opReqGetAsync(paramObject, acct, callback) {
var baseURL = window.location.protocol+"//"+window.location.hostname+"/observepointcustomtag?acct=" + acct;
var opReq = new XMLHttpRequest();
opReq.onreadystatechange = function() {
if (opReq.readyState === 4 && opReq.status === 200) {
callback(opReq.responseText);
}
}
opReq.open("POST", baseURL, true);
opReq.send(JSON.stringify(paramObject));
}
////////////////////////////////////////////////// Above is script that fires the OP Custom Tag, you should NOT modify it /////////////////////////////////////////////////////
//The Javascript object below is what you build and send to ObservePoint
var objQP = {};
// Gets the URL
const queryParam = window.location.href
// Parses the URL string into the data that we want, separate in "key=value" style, but not fully separated yet, and turns it into an array of "key=value" values
const splitArr = queryParam.split("?")[1].split("&")
// Takes the splitArr array, parses each value further, and then pushes the properties into obj{}
var arrToObj = splitArr.forEach(function(x) {
var key = x.split("=")[0]
var value = x.split("=")[1]
objQP[key] = value
})
opReqGetAsync(objQP, 'Query Parameters');