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
  • 16424 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 3, 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);

                }

            });

Adobe Employee
November 6, 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.


I think I may have missed part of your question above. The adobe.target.applyOffer({offer: response}); will simply apply the content change Target returns in that getOffer. If there is no test that a visitor qualifies for then nothing will happen. If they qualify for a test with content changes then that line allows the at.js file to load that content in the predefined location of the page.