Visualizzazione del contenuto dell'aiuto per la versione :

This section describes topics about developing components for use with content targeting.


When you target a component in AEM author, the component makes a series of server-side calls to Adobe Target to register the campaign, set up offers, and retrieve Adobe Target segments (if configured). No server-side calls are made from AEM publish to Adobe Target.

Enabling Targeting with Adobe Target On Your Pages

To use targeted components in your pages that interact with Adobe Target, include specific client-side code in the <head> element.

The head Section

Add both of the following code blocks to the <head> section of your page:

<!--/* Include Context Hub */-->
<sly data-sly-resource="${'contexthub' @ resourceType='granite/contexthub/components/contexthub'}"/>
<cq:include script="/libs/cq/cloudserviceconfigs/components/servicelibs/servicelibs.jsp"/>

This code adds the required analytics javascript objects and loads the cloud service libraries associated with the web site. For Target service, the libraries are loaded via /libs/cq/analytics/components/testandtarget/headlibs.jsp 

The set of libraries loaded depend on the type of target client library (mbox.js or at.js) used on Target configuration:

For default mbox.js

<script type="text/javascript" src="/etc/clientlibs/foundation/testandtarget/parameters.js"></script>
	<script type="text/javascript" src="/etc/clientlibs/foundation/testandtarget/mbox.js"></script>
	<script type="text/javascript" src="/etc/clientlibs/foundation/personalization/integrations/commons.js"></script>
	<script type="text/javascript" src="/etc/clientlibs/foundation/testandtarget/util.js"></script>
	<script type="text/javascript" src="/etc/clientlibs/foundation/testandtarget/init.js"></script>

For custom mbox.js

<script type="text/javascript" src="/etc/cloudservices/testandtarget/<CLIENT-CODE>/_jcr_content/public/mbox.js"></script>
        <script type="text/javascript" src="/etc/clientlibs/foundation/testandtarget/parameters.js"></script>
	<script type="text/javascript" src="/etc/clientlibs/foundation/personalization/integrations/commons.js"></script>
	<script type="text/javascript" src="/etc/clientlibs/foundation/testandtarget/util.js"></script>
	<script type="text/javascript" src="/etc/clientlibs/foundation/testandtarget/init.js"></script>

For at.js

<script type="text/javascript" src="/etc/clientlibs/foundation/testandtarget/parameters.js"></script>
	<script type="text/javascript" src="/etc/clientlibs/foundation/testandtarget/atjs-integration.js"></script>
	<script type="text/javascript" src="/etc/clientlibs/foundation/testandtarget/atjs.js"></script>

For custom at.js

<script type="text/javascript" src="/etc/cloudservices/testandtarget/<CLIENT-CODE>/_jcr_content/public/at.js"></script>
   	<script type="text/javascript" src="/etc/clientlibs/foundation/testandtarget/parameters.js"></script>
	<script type="text/javascript" src="/etc/clientlibs/foundation/testandtarget/atjs-integration.js"></script>

The Target functionality on the client side is managed by the CQ_Analytics.TestTarget object. Therefore, the page will contain some init code such as in the following example:

<script type="text/javascript">
            if ( !window.CQ_Analytics ) {
                window.CQ_Analytics = {};
            if ( !CQ_Analytics.TestTarget ) {
                CQ_Analytics.TestTarget = {};
            CQ_Analytics.TestTarget.clientCode = 'my_client_code';
    <div class="cloudservice testandtarget">
		<script type="text/javascript">
		CQ_Analytics.TestTarget.maxProfileParams = 11;

		if (CQ_Analytics.CCM) {
			if (CQ_Analytics.CCM.areStoresInitialized) {
			} else {
				CQ_Analytics.CCM.addListener("storesinitialize", function (e) {
		} else {
			// client context not there, still register calls

Using a Custom Target library file


If you are not using DTM or another target marketing system, you can use custom target library files.


By default, mboxes are hidden - the mboxDefault class determines this behavior. Hiding mboxes ensures that visitors do not see the default content before it is swapped; however, hiding mboxes impacts perceived performance.

The default mbox.js file that is used to create mboxes is located at /etc/clientlibs/foundation/testandtarget/mbox/source/mbox.js. To use a customer mbox.js file, add the file to the Target cloud configuration. To add the file, the mbox.js file must be available on the file system.

For example, if you want to use the Marketing Cloud ID service you need to download mbox.js so that it contains the correct value for the imsOrgID variable, which is based on your tenant. This variable is required for integrating with the Marketing Cloud ID service. For information, see Adobe Analytics as the Reporting Source for Adobe Target and Before You Implement.


If a custom mbox is defined in a Target configuration, everyone must have read access to /etc/cloudservices on publish servers. Without this access, loading mbox.js files on publish website results in a 404 error. 

  1. Go to the CQ Tools page and select Cloud Services. (http://localhost:4502/libs/cq/core/content/tools/cloudservices.html)

  2. In the tree, select Adobe Target, and in the list of configurations, double-click your Target configuration.

  3. On the configuration page, click Edit.

  4. For the Custom mbox.js property, click Browse and select the file.

  5. To apply the changes, enter the password for your Adobe Target account, click Re-connect To Target, and click OK when the connection is successful. Then, click OK on the Edit Component dialog box. 

Your Target configuration includes a custom mbox.js file, the required code in the head section of your page adds the file to the client library framework instead of a reference to the testandtarget.js library.

Disabling the Target Command for Components

Most components can be converted to targeted components using the Target command on the context menu.


To remove the Target command from the context menu, add the following property to the cq:editConfig node of the component:

  • Name: cq:disableTargeting
  • Type: Boolean
  • Value: True

For example, to disable targeting for the title components of the Geometrixx Demo Site pages, add the property to the /apps/geometrixx/components/title/cq:editConfig node.


Sending Order Confirmation Information to Adobe Target


If you are not using DTM, you send order confirmation to Adobe Target. 

For tracking the performance of your website, send purchase information from your order confirmation page to Adobe Target. (See Create an orderConfirmPage Mbox in the Adobe Target documentation.) Adobe Target recognizes mbox data as order confirmation data when your MBox name is orderConfirmPage and uses the following specific parameter names:

  • productPurchasedId: A list of IDs that identify the purchased products.
  • orderId: The ID of the order.
  • orderTotal: The total amount of the purchase.

The code on the rendered HTML page that creates the mbox is similar to the following example:

<script type="text/javascript">
     'productPurchasedId=product1 product2 product3',

The values of each parameter are different for each order. Therefore, you require a component that generates the code based on the properties of the purchase. The CQ eCommerce Integration Framework enables you to integrate with your product catalogue and implement a shopping cart and checkout page. 

The Geometrixx Outdoors sample displays the following confirmation page when a visitor purchases products:


The following code for the JSP script of a component accesses the properties of the shopping cart and then prints the code for creating the mbox.


  confirmationmbox component.

%><%@include file="/libs/foundation/global.jsp"%><%
%><%@page session="false"
                  java.util.List, java.util.Iterator"%><%

/* obtain the CommerceSession object */                     
CommerceService commerceservice = resource.adaptTo(CommerceService.class);
CommerceSession session = commerceservice.login(slingRequest, slingResponse);

/* obtain the cart items */
List<CommerceSession.CartEntry> entries = session.getCartEntries();
Iterator<CommerceSession.CartEntry> cartiterator = entries.iterator();

/* iterate the items and get the product IDs */
String productIDs = new String();
	CommerceSession.CartEntry entry =;
	productIDs = productIDs + entry.getProduct().getSKU();
    if (cartiterator.hasNext()) productIDs = productIDs + ", ";

/* get the cart price and orderID */
String total = session.getCartPrice(new PriceFilter("CART", "PRE_TAX"));
String orderID = session.getOrderId();

%><div class="mboxDefault"></div>
<script type="text/javascript">
     'productPurchasedId=<%= productIDs %>',
     'orderId=<%= orderID %>',
     'orderTotal=<%= total %>');

When the component is included in the checkout page in the previous example, the page source includes the following script that creates the mbox:

<div class="mboxDefault"></div>
<script type="text/javascript">
     'productPurchasedId=47638-S, 46587',


Understanding the Target Component

The Target component enables authors to create dynamic mboxes from CQ content components. (See Content Targeting.) The Target component is located at /libs/cq/personalization/components/target.

The target.jsp script accesses the page properties to determine the targeting engine to use for the component, and then executes the appropriate script:

  • Adobe Target: /libs/cq/personalization/components/target/engine_tnt.jsp
  • Adobe Target with AT.JS: /libs/cq/personalization/components/target/engine_atjs.jsp
  • Adobe Campaign: /libs/cq/personalization/components/target/engine_cq_campaign.jsp
  • Client-side Rules/ContextHub: /libs/cq/personalization/components/target/engine_cq.jsp

The Creation of Mboxes


By default, mboxes are hidden - the mboxDefault class determines this behavior. Hiding mboxes ensures that visitors do not see the default content before it is swapped; however, hiding mboxes impacts perceived performance.

When Adobe Target drives content targeting, the engine_tnt.jsp script creates mboxes that contain the content of the targeted experience:

  • Adds a div element with the class of mboxDefault, as required by the Adobe Target API. 
  • Adds the mbox content (the content of the targeted experience) inside the div element.

Following the mboxDefault div element, the javascript that creates the mbox is inserted:

  • The mbox name, ID, and location are based on the repository path of the component.
  • The script obtains Client Context parameter names and values.
  • Calls are made to the functions that mbox.js and other client libraries define to create mboxes. 

Client Libraries for Content Targeting

The following are the available clientlib categories:

  • testandtarget.mbox
  • testandtarget.init
  • testandtarget.util
  • testandtarget.atjs
  • testandtarget.atjs-integration

Questo prodotto è concesso in licenza in base alla licenza di Attribuzione-Non commerciale-Condividi allo stesso modo 3.0 Unported di Creative Commons.  I post su Twitter™ e Facebook non sono coperti dai termini di Creative Commons.

Note legali   |   Informativa sulla privacy online