Highlighted

Targeting DOM element and cookie

Avatar

Avatar

sabahatu1546489

Avatar

sabahatu1546489

sabahatu1546489

25-10-2017

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,

Replies

Highlighted

Avatar

Avatar

sabahatu1546489

Avatar

sabahatu1546489

sabahatu1546489

25-10-2017

ryanr8​ could you help please

Highlighted

Avatar

Avatar

ryanr701

Employee

Avatar

ryanr701

Employee

ryanr701
Employee

31-10-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!

Highlighted

Avatar

Avatar

sabahatu1546489

Avatar

sabahatu1546489

sabahatu1546489

01-11-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");

   }

Highlighted

Avatar

Avatar

ryanr701

Employee

Avatar

ryanr701

Employee

ryanr701
Employee

01-11-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()

Highlighted

Avatar

Avatar

sabahatu1546489

Avatar

sabahatu1546489

sabahatu1546489

01-11-2017

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")

            }

          }

}

      

   }

Highlighted

Avatar

Avatar

sabahatu1546489

Avatar

sabahatu1546489

sabahatu1546489

01-11-2017

ryanr8​ any luck with that?

Avatar

Avatar

ryanr701

Employee

Avatar

ryanr701

Employee

ryanr701
Employee

01-11-2017

Entity and profile should be at the same level. Also, I don't see the targetPageParams function. It should probably be after your if condition.

Also, the quick way to debug is to monitor the mbox requests from the page this is running. Can you see the expected url parameters on that mbox request? Is "entity.id=X" showing? Is "profile.TFuser=Y" showing? If they are you will see them show up in the drop down, but that sometimes takes a few minutes to reflect the newest data.

Highlighted

Avatar

Avatar

sabahatu1546489

Avatar

sabahatu1546489

sabahatu1546489

03-11-2017

I have been trying to wrap my head around "manually firing a getOffer: adobe.target.getOffer(options)"

I tried some thing like this with google search but can't seem to figure out what would be the name or Api of the Offer I need to use inside adobe.target.applyOffer({offer: response});

Could you please give an example if I am using this to check the existence of the DOM element and then returning profile.DOMelement

adobe.target.getOffer({

                mbox: 'target-global-mbox',

                success: function(response) {

                    console.log('Response:', response); 

                    adobe.target.applyOffer({offer: response});

                },

                error: function(status, error) {

                    console.log('Error:', status, error);

                }

            });

Highlighted

Avatar

Avatar

ryanr701

Employee

Avatar

ryanr701

Employee

ryanr701
Employee

06-11-2017

Hi,

Sorry if I was confusing. I mean that you could do your DOM element check on the page and then if it returns true you could then send that as a parameter to Target via a getOffer function. Target can also use this "secondary" call to qualify a visitor for a test and return a content change to the page. Though because it is a secondary call the built in flicker handling Target has will not be in play so you may see content changes flicker in this case.

That said this is what I'd try:

//DOM element checker coder runs, then if true call the getOffer

adobe.target.getOffer({

  mbox: 'target-global-mbox',

  params: {'requestType':'secondary','profile.DOMElement':'true'},

  success: function(response) {

   //console.log('Second response back from Target');

   adobe.target.applyOffer({offer: response});

  },

  error: function(status, error) {

    console.log('Error', status, error);

  }

});

You can uncomment the console.log under success if you like for debugging. I also added a parameter called requestType since I used the target-global-mbox name. This will allow you to create an audience to limit a test to just requests that come with this getOffer, rather than the auto-created version of this mbox that fires on every page.