All Collections
ObservePoint Custom Tag
OP Custom Tag - Key Word Search
OP Custom Tag - Key Word Search
Luiza Gircoveanu avatar
Written by Luiza Gircoveanu
Updated over a week ago

Summary

This ObservePoint Custom Tag allows you to search for keywords and flag pages where those keywords are found. Using the javascript snippet below in the Audit Actions configuration will fire a tag that collects your keywords, as variables with the value of true/false if that keyword is present at least once on the page.

Note: The key word search is case agnostic, so it will identify lowercase and uppercase variants of the key words. You will need to modify this Javascript by defining the key words you want to search for in the array.

//add key words to this array (separated by commas) and customize the tag account name

var words = ["Insert key Word 1", "Insert key Word 2", "Insert key Word 3"];
var tagAccountName = 'Key Word Search';

/////////////////////////////////////////////////////////////////////////////////
/* DON'T MODIFY ANYTHING BELOW */
/////////////////////////////////////////////////////////////////////////////////

var obj = {};
var dom = document.documentElement.innerText.toLowerCase(); //don't touch this

words.forEach((word) => {
if (dom.includes(word.toLowerCase())) {
obj[word.toLowerCase()] = true;
} else {
obj[word.toLowerCase()] = false;
}
})

opReqGetAsync(obj, tagAccountName);

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));
}
Did this answer your question?