Targeting DOM element and cookie | Community
Skip to main content
sabahatu1546489
Level 2
October 25, 2017

Targeting DOM element and cookie

  • October 25, 2017
  • 2 replies
  • 16423 views

Hi there,

We are trying to target DOM element and cookie value through targetPageParams() function. Essentially we want to do that for 2 separate experiments. You can see the code below. We can see "trackCookie" coming up under Visitor Profile but "DOMElement" is not coming up. Could you please help us out here

function targetPageParams() {

    if(location.pathname.indexOf("contact") > -1){

        var timer = setInterval(function(){

            if($(".ttt:contains('T12')").length > 0){

                clearInterval(timer);

                return "profile.DOMElement=true"; 

            }

        }, 100);

    }else{

        function readCookie(name) {

            var nameEQ = name + "\x3d";

            var ca = document.cookie.split(";");

            for (var i = 0; i < ca.length; i++) {

                var c = ca[i];

                while (c.charAt(0) == " ") c = c.substring(1, c.length);

                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length)

            }

            return null

        }

        return "profile.trackCookie=" + readCookie("superman");

    }

}

Thanks,

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

sabahatu1546489
Level 2
October 25, 2017

ryanr8​ could you help please

Adobe Employee
October 31, 2017

Looks like you are trying to add a delay in the targetPageParams function. I'd suspect this is why you don't see the DOMElement attribute showing. The targePageParams function cannot way for DOM elements to exist before returning a value. Target's call to the server will have already happened.

If you are trying to check the presence of a DOM element and send that info back to Target as a flag you probably will need to do this in a secondary call to Target (the auto created global mbox call fires before the body gets loaded - this is to prevent content changes from causing flicker).

See help for manually firing a getOffer: adobe.target.getOffer(options). Pass the profile.DOMElement in the params section.Hope that helps!

sabahatu1546489
Level 2
November 1, 2017

ryanr8 Thanks for your reply. I'll give it try now.

but could you tell how we can return multiple values under targetPageParams function

for example we are passing prodct id and category for recommendation and

at the same time we want to return the read cookie function. now the funtciton allows only one return statement.

How can we go about doing this.

if(document.URL.indexOf("productdetailpage") > -1){

       return{

          "entity": {

            "id": prodID,

            "categoryId": categoryID,

          }

}

       // how can we pass this below return statement as well

        return "profile.trackCookie=" + readCookie("superman");

   }

sabahatu1546489
Level 2
November 1, 2017

Your return can contain a list of parameters that get added.

function targetPageParams() {

  return "param1=value1&param2=value2&p3=hello%20world";

}

There are more ways to format your return. You can see examples in help: targetPageParams()


ryanr8​ bit stuck here. I tried the following way but I don't see the that profile in the audience list. Could you please help

if(document.URL.indexOf("productdetailpage") > -1){

       return{

          "entity": {

            "id": prodID,

            "categoryId": categoryID,

              "profile": {

                "TFuser" : readCookie("superman")

            }

          }

}

      

   }