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

ryanr701

Employee

Avatar

ryanr701

Employee

ryanr701
Employee

06-11-2017

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.

Highlighted

Avatar

Avatar

sabahatu1546489

Avatar

sabahatu1546489

sabahatu1546489

06-11-2017

certainly we are going on a right direction. building the perspective will be even helpful. I think I am just missing something here. Please let me know what part is it?

in short: we want to launch an activity based on the DOM element

(I understand targetpageparam() is not feasible becuse of timing. I get that. adobe.target.applyOffer can be used although flicker is expected with it. I get that too.)

In order to use adobe.target.applyOffer and adobe.target.getOffer

In Target dashboard

1- Under Offers, I save the javascript code for example to alter the "add to bag color and size" on Product details page (PDP) .

2- Then I run an Activity on Product details page (PDP) that would contain the code you supplied in your last reply. This code will basically activate the offer I saved in my last step.

https://codepen.io/sabahat88/pen/aVZMvK?editors=0010

The getOffer, you are running it as DOM checker but where the code for actually checking the DOM element would go? like the one below.

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

               

            }

Please let me know

Highlighted

Avatar

Avatar

ryanr701

Employee

Avatar

ryanr701

Employee

ryanr701
Employee

07-11-2017

Assuming you are using the VEC instead of form based - You can use a Target activity to add the DOM element checker and getOffer function to the PDP. Create an activity on the PDP and use insert element (HTML) to an element that will exist below the element you are looking for (for timing purposes). The HTML you add should be a script tag with something like this:

This will fire another target-global-mbox request IF the DOM Element exisits and you create a second Target Activity to respond on this call.

The first activity should have an audience defined where the custom attribute > target-global-mbox > requestType > parameter doesn't exist - this prevents it from getting returned in the secondary call.

The second activity is where you apply the content changes you want to test/personalize. It needs an audience defined where custom attribute > target-global-mbox > DOMElement contains true. So a visitor only qualifies when the DOM element exists.

I'm guessing you'd want to check for the DOMElement on each page view of a PDP and not just once per visitor. So there's no use sending it as a "profile." attribute.

Highlighted

Avatar

Avatar

sabahatu1546489

Avatar

sabahatu1546489

sabahatu1546489

10-11-2017

ryanr8 HI Ryan, Okay I have launched an Activity with DOM element checker and getOffer function code as you said.
The DOM element "T12" exists right after body opening tag. The DOM checker and getOffer function was added in VEC by clicking on element way after 'T12' and yes I added the code under script tags
but for audience as you said:

"The first activity should have an audience defined where the custom attribute > target-global-mbox > requestType > parameter doesn't exist - this prevents it from getting returned in the secondary call." and

I don't see this audience coming up in Audience list.. (nor in the mbox Network call).

secondly audience "custom attribute > target-global-mbox > DOMElement contains true" for the second activity, is not showing up as well.

I still saved both experiment by adding these audiences but its not working.

Could you help please?

Thanks

Highlighted

Avatar

Avatar

ryanr701

Employee

Avatar

ryanr701

Employee

ryanr701
Employee

10-11-2017

Yes, you have to create a new audience with the definition I supplied.

1345616_pastedImage_14.png

The same is true for the DOMelement audience too. NOTE that requestType will only show up in the drop down if Target has seen that parameter on a request for the target-global-mbox. So you'll need to add the code and load a page with the code so it fires before you'll be able to fully define the new audience.