Profile Script - Element exists



I'm trying to create a profile script that checks to see if an element on the current page exists. If the element exists then the code returns true. I'm having difficulty getting my code to work without getting the "element undefined" error. Does anyone have any tips to get this script to work? If accessing page elements through the profile script is not possible; I'm wondering if there is a way to profile users through an offer? Any help is appreciated.


if ( == 'my_mbox'){ var hasClass = element.classList.contains('.mydiv'); if (hasClass === true) { return true; } }

Accepted Solutions (1)

Accepted Solutions (1)



Hi Paul,

There are many ways to do this. You can pass your offer code by URL, Page Parameter, mBox Parameter.

By URL : return page.param("offercode"); (Profile Script)

By Page Parameter : (Page level Code)

targetPageParams = function() { return { "offercode": 1451 }; };

Check this

By mBox Parameter (Page level Code)


Check this 

You can find the offercode parameter under audience -> visitor profile


Rajarajan R

Answers (2)

Answers (2)



Hi Paul,

Script profile code is executed everytime an mbox request is received. If your mbox is defined before the element you want to check, chances are your script execution will return 'element undefined' error.

To avoid this, you can use mboxUpdate() within your offer code. Make sure offer code is set to be executed when target element has been loaded. Example is :

    if (mboxFactoryDefault.getMboxes().get("newMbox").length()===0){
        var d = document.createElement("div"); = "newMbox_div";


You can then set your profiles on the basis of attribute1 and value1. Hope this helps,