Profile Script - Element exists | Community
Skip to main content
January 20, 2016
Solved

Profile Script - Element exists

  • January 20, 2016
  • 3 replies
  • 2813 views

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 (mbox.name == 'my_mbox'){ var hasClass = element.classList.contains('.mydiv'); if (hasClass === true) { return true; } }
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by rajarajanr71853

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 https://marketing.adobe.com/resources/help/en_US/target/ov/c_pass_parameters_to_global_mbox.html

By mBox Parameter (Page level Code)

mboxCreate('mboxname','offercode=15463');

Check this https://marketing.adobe.com/resources/help/en_US/target/ov/t_orderconfirm_create.html 

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

 

Rajarajan R

3 replies

Level 2
February 4, 2016

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 :

mboxFactoryDefault.addOnLoad(function(){
    if (mboxFactoryDefault.getMboxes().get("newMbox").length()===0){
        var d = document.createElement("div");
        d.id = "newMbox_div";
        document.body.appendChild(d);
        mboxDefine("newMbox_div","newMbox");
    }
    mboxUpdate("newMbox","attribute1=value1");
});

 

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

Rajneesh

February 5, 2016

Thank you for the reply Rajneesh. I'm a bit confused on how I tie the offer code to the profile code. Can you please provide an example?

rajarajanr71853
rajarajanr71853Accepted solution
Level 2
February 9, 2016

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 https://marketing.adobe.com/resources/help/en_US/target/ov/c_pass_parameters_to_global_mbox.html

By mBox Parameter (Page level Code)

mboxCreate('mboxname','offercode=15463');

Check this https://marketing.adobe.com/resources/help/en_US/target/ov/t_orderconfirm_create.html 

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

 

Rajarajan R