Skip to main content
billc52928879
September 14, 2017

Is there a way to add conditional activation for activities?

  • September 14, 2017
  • 1 reply
  • 16619 views

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?

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

1 reply

Amelia_Waliany
Adobe Employee
Adobe Employee
September 18, 2017

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.

aellis82
Level 2
April 10, 2018

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

Level 2
April 18, 2018

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


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

    });

  }

});