Expand my Community achievements bar.

Applications for the 2024 Adobe Target Community Mentorship Program are open! Click to the right to learn more about participating as either an Aspirant, to professionally level up with a new Certification, or as a Mentor, to share your Adobe Target expertise and inspire through your leadership! Submit your application today.

Is there a way to add conditional activation for activities?

Avatar

Level 1

Let's say I only wanted to run an activities on pages where a certain DOM element exists (and there's no URL pattern that could be used for the "Page Delivery") - is there any way in Target to use a custom script to activate the activity?

11 Replies

Avatar

Administrator

Greetings, thanks for your question! For a VEC-based Activity, you need a URL to import the Activity. To learn more about whether it is possible to override the URL here, visit Visual Experience Composer Best Practices and Limitations. If the same DOM element ID is used on multiple elements on the page, changing one of those elements changes all elements with that ID. To prevent this from happening, an ID should be used only once on each page. This is a standard HTML best practice; for more information, see Page Modification Scenarios. For a Form-based Activity, you can use a custom script to run the Activity - just make sure to include the mboxCreate on the page.

Avatar

Level 2

Hello,

this question very much relates to our problem, but the response does not solve our problem and we'd really appreciate some help.

We're new to target and would help with setting up conditional activation of an A/B experiment.

We only wish to include visitors in the experiment when there are less than 3 instances of a particular div element on the page.

We can count the elements using $('.x').length where x is a class.

However we are unclear on how to target users for this particular scenario only. Currently, everyone who visits the page is included in the experiment, regardless of how many of this particular element are present and this isn't what we need.

Please help.

thanks,

Andrew

Avatar

Employee

Hi Andrew

So, these elements are dynamic? Some see 1, others see 2 or 3?

I would say that it might be a good option to see if something can be added in URL parameters based on the same business logic which is changing these element counts. Is that not doable?

Can you explain your use case bit more? What are these divs an?

Avatar

Level 1

Hi Andrew,

The decision of campaign qualification happens on Edge server. Now to achieve the use case you can try to leverage presence of DOM element to set a parameter in mbox call which therefore can be used to decide campaign qualification.

Something Like:

targetPageParams: function() {

isElementPreset: $('#myElementId').length

}

Now the mbox parameter can be used to create a qualification audience isElementPreset > 3

Hope that answers your query

Avatar

Community Advisor

Hi there,

There are 2 possible solutions to your challenge, depending upon where data, on basis of which conditional activation needs to happen, is present.

1. If data is present before Global mbox is created:

If you have follwed best practice, Target library would sit in <HEAD>. In this case conditional activation data must be present before Target library. A common example for this is Data-layer objects. So if activty's activation is driven by rules that are defined using your Data-layer attributes, you can use targetPageParams method (See link below for more details).

Passing Parameters to a Global mbox

This method is used to set parameters which are passed to Global mbox when its requested to be created. It has to be set before the mbox Create call - use your Tag Management System for this purpose.

Passed variables then can be used to create Audiences (you will have to use Custom under Rule type).

2. If data is present after Global mbox is created:

In certain scenarios like presence of a <div> for qualifting a visitor for an activity, you cannot use targetPageParams approach as Global mbox is already created. In this case, you should  use following approach:

2.1 Create an activity (lets call it Activity A for now) using Global mbox which has All Visitors as Audiences and runs on the same page where particular <div> is present.

2.2 Code for this Activity A should search for the <div> presence and should call mboxUpdate(), passing an mbox parameter which suggests that condition for activity activation is true. Here’s the code I used:

var d = document.createElement("div");

d.id = "your-mbox-name_div";

document.body.appendChild(d);

mboxDefine(“your-mbox-name_div","your-mbox-name");

mboxUpdate("your-mbox-name","conditionalActivation=true");

2.3 Take Activity A live.

2.4 Setup an Audience on the basis of mbox used in step 2.2 and mbox parameter passed (you will have to use Custom under Rule type)

2.5 Now create a new Activity B that uses above mentioned mbox and Audience. This is your main activity where experience should change on the basis of conditional activation. As visitors get qualified only when <div> is present, your Visitor count should be accurate.

Hope this helps,

Rajneesh

Avatar

Level 2

Thanks Ranjeesh,

really appreciate you taking the time to reply to this.

We've gone down the route of the second approach you mentioned. However, Activity B does not seem to be activating based on the Audience set by Activity A. The mBox has been created successfully on the page, the Audience conditions have been setup against Activity B, but when the page loads, it does not move from Activity A. And no matter what we do, we can't seem to trigger Activity B.

Any thoughts?

thanks,

Andrew

Avatar

Community Advisor

Hi Andrew, it could be a bit difficult to troubleshoot without looking at activity configuration so will try to share some potential next steps:

1. Check that your activity is not restricted by any Property-rules. Mbox updated through mboxUpdate() may not have at_property variable sent.

2. Check  mboxTrace to ensure you are qualifying for all required audiences

3. You havent got any Activity based audiences on that conflict with Experience Audiences.

Please DM me in case you want me to look into it in more details

Regards,

Rajneesh

Avatar

Employee

Hi Andrew,

Adding to the above, you need to use an XT campaign within Target to achieve the above. If you are using an A/B campaign then the user will be tied to the experience user is viewing. So if i see Experience A on first visit then I am tied to this experience.

~Rohit

Avatar

Level 2

Hi Andrew,

not sure if this helps but i'll share the solution we use for loading campaigns dynamically; we create 2 activities where one acts as a 'gateway' with conditional logic to load the actual activity with the test.


Here's the rough  outline of the code for the 'gateway' activity - note help-modal-test-mbox is the custom mbox used as the location in activity with the actual test:

jQuery(document).ready(function(){

  if(jQuery('#help-modal').length){

    // next part fecthes our actual offer there could be a delay so you need to be mindful of the impact to user i.e. hide/show or add a message whilst its loading

    adobe.target.getOffer({ 

      "mbox": "help-modal-test-mbox", // we create a custom mbox for our offer

      "success": function(offers) {

            // note you might want to add logic here to check an offer was returned (offer is an array)

            adobe.target.applyOffer( {

               "mbox": "help-modal-test-mbox",

               "offer": offers

            } );

      }, 

      "error": function(status, error) {         

         

          // fallback

          if (console && console.log) {

            console.log(status);

            console.log(error);

          }

         

      },

     "timeout": 5000

    });

  }

});

Avatar

Community Advisor

Hi Richard, really helpful to see see the code, thanks for sharing.

While this code serves the purpose of dynamic offere presentattion, it will still have skewed visitors count as 'Gateway' activity will be shown to everyone. Andrew is also looking to ensure that visitor count in their activity is just genuinely qualified visitors "We only wish to include visitors in the experiment when there are less than 3 instances of a particular div element on the page."

Can you please confirm my understanding?

Regards,

Rajneesh

Avatar

Level 2

Hi Rjanesh no problem hope it was of some assistance.

The gateway offer and dynamic offer are using same audience however the dynamic offer is setup to split traffic 50/50 between A/B experiences and from testing that seems to be working

Cheers

Richard