This section includes the available classes and examples.
Methods
constructor
For a complete configuration of the Mapp Intelligence Java library please check Configuration.
/**
* @param config Mapp Intelligence configuration
*/
MappIntelligenceTracking mappIntelligence = new MappIntelligenceTracking(MappIntelligenceConfig config);track
Requests are collected in internal queues and sent at defined intervals, via flush call or when the instance is closed (see close). For a complete data configuration of the Mapp Intelligence Java library, please check Data.
The return value is the ID of the request queue the request was added to (0 to the value of requestQueues), or -1 if the request was not added: tracking is deactivated, the track ID or track domain is missing, the include/exclude filters exclude the request URL, the data is null, or the instance is already closed.
/**
* @return Integer Request queue ID
*/
mappIntelligence.track();/**
* @param data Mapp Intelligence parameter map
*
* @return Integer Request queue ID
*/
mappIntelligence.track(MappIntelligenceParameterMap data);/**
* @param data Mapp Intelligence data map
*
* @return Integer Request queue ID
*/
mappIntelligence.track(MappIntelligenceDataMap data);flush
Here you can explicitly tell to send the data to the Mapp tracking servers.
The call is best effort: it only hands the queued requests to the background threads and returns immediately, it does not wait until they are sent. Use close if the requests have to be handed to the consumer before you continue. After close, flush() sends nothing and logs a warning.
/**
*
*/
mappIntelligence.flush();setOnFlushComplete
Here you can define a callback method that is automatically called after each flush. The first argument is the status of the request dispatch. The second argument specifies which queue was involved.
The status is also false if a batch of that queue was discarded because it can never be sent (for example a permanent client error). Besides flush, the periodic flush of requestInterval and close call the callback as well. It runs on the background thread of the queue, so it must be thread-safe.
/**
* @param callback Callback for complete flushing
*/
mappIntelligence.setOnFlushComplete(BiConsumer<Boolean, Integer> callback);close
Sends all remaining requests, waits up to 30 seconds for them to be handed to the consumer and releases the thread pools and the file handle of the file consumer. The call is idempotent; after it, track returns -1 and requests are no longer accepted (each rejected request is logged at level ERROR).
The 30 seconds are one deadline shared by all queues and include the retries (maxAttempt × attemptTimeout) and the time the consumer needs. If it expires, a warning is logged and the consumer is closed anyway; requests that are still being sent at that moment are lost.
A consumer that you passed in via the configuration (setConsumer) is not closed by the library. An instance that is never closed sends its remaining requests only once it has been garbage collected or the JVM terminates, and there is no guarantee when that happens.
/**
*
*/
mappIntelligence.close();Example
try (MappIntelligenceTracking mappIntelligence = new MappIntelligenceTracking(mappConfig)) {
mappIntelligence.track(dataMap);
}getUserIdCookie
It is important to uniquely identify a user to fully benefit from Mapp Intelligence tracking capabilities. Mapp Intelligence uses the everID (eid) internally to keep the tracking information aligned to a user. You can either pass your own unique identifier or you can use the library to use an existing everID (see Configuration → setCookie). If you track with both the server-side library and the pixel and you use the getUserIdCookie() method, an eid cookie is returned (see MappIntelligenceCookie), which you then returned to the client.
A cookie is only returned if the user has no everID yet; the library then generates one. Call the method before track, so that the generated everID is also sent with the request. The method returns null if an everID already exists (from the cookies of the request), if the track ID or track domain is missing, if the pixel version is unknown (client side), or, with MappIntelligence.SERVER_SIDE_COOKIE, if the track domain is a Mapp domain (for example *.wt-eu02.net) instead of your own tracking domain. In the last two cases, an everID is still generated and sent with the requests.
Pixel version / context | Cookie name | Value | Domain |
|---|---|---|---|
|
| the everID | – |
|
| the existing | – |
any, |
| the everID | the track domain without its first label ( |
All returned cookies have a max age of 180 days (15,552,000 seconds) and the path /, and they are always Secure and HttpOnly.
Options
MappIntelligence.V4 | pixelVersion |
MappIntelligence.V5 | pixelVersion |
MappIntelligence.SMART | pixelVersion |
MappIntelligence.CLIENT_SIDE_COOKIE | context |
MappIntelligence.SERVER_SIDE_COOKIE | context |
/**
* @param pixelVersion Version ot the current pixel (v4, v5, smart)
* @param context Cookie context (1, 3)
*
* @return MappIntelligenceCookie
*/
MappIntelligenceCookie mappCookie = mappIntelligence.getUserIdCookie(String pixelVersion, String context);getTransmittedCampaignsCookie
Required if you use MappIntelligenceCampaign.setOncePerSession(true) (see Campaign). The library remembers the campaigns already transmitted in this session in the cookie wtstp_tcc. The method returns this cookie (see MappIntelligenceCookie) after a new campaign was transmitted, otherwise null. You have to add it to the HTTP response yourself, before the response is committed, otherwise "once per session" cannot work across requests.
The cookie is a session cookie (max age -1) with the path /, not HttpOnly (the pixel reads it as well), and secure unless the request URL is plain HTTP. Only track(MappIntelligenceDataMap) with a campaign object evaluates "once per session"; a request sent with a MappIntelligenceParameterMap never changes the cookie.
/**
* @return MappIntelligenceCookie or null
*/
MappIntelligenceCookie campaignsCookie = mappIntelligence.getTransmittedCampaignsCookie();Example
MappIntelligenceCookie campaigns = mappIntelligence.getTransmittedCampaignsCookie();
if (campaigns != null) {
Cookie cookie = new Cookie(campaigns.getName(), campaigns.getValue());
cookie.setPath(campaigns.getPath());
cookie.setSecure(campaigns.isSecure());
cookie.setHttpOnly(campaigns.isHttpOnly());
cookie.setMaxAge(campaigns.getMaxAge());
response.addCookie(cookie);
}Methods
constructor
For a complete configuration of the Mapp Intelligence Hybrid please check Configuration.
The hybrid writes the requests into log files that you send with the Cron Job: the constructor sets the consumer type of the configuration that you pass in to FILE, unless it is CUSTOM. This changes your configuration object: maxBatchSize becomes 1, and filePath and filePrefix get their defaults if they are empty.
/**
* @param config Mapp Intelligence configuration
*/
MappIntelligenceHybrid mappIntelligenceHybrid = new MappIntelligenceHybrid(MappIntelligenceConfig config);track
Reads all query parameters from the current request URL (see setRequestURL in Configuration) and saves the request in the internal queues, which are sent at defined intervals, via flush call or when the instance is closed. The return value is the request queue ID, or -1 if nothing was added.
Only pixel requests are accepted: the query string has to contain the pixel parameter
pwith a value and may be at most 64 KB (see isValidPixelRequest). Any other request is ignored (logged at level WARN) instead of being written into the log files.The parameters that only the server may set are removed from the client request first:
X-WT-IP,X-WT-UAandX-WT-SEC-CH-UA*, so a client cannot pretend to be another user. The library then adds user agent, IP address and client hints from the configuration, if they are set there.track(String rURL)with a malformed URL ornulldoes not track anything and returns-1. The previous request URL is not tracked again.Unlike
MappIntelligenceTracking, the hybrid does not add the everID (eid), because the pixel requests carry their own. It also does not check the track ID or track domain and does not apply the include/exclude filters.
mappIntelligenceHybrid.track();/**
* @param rURL request url with query parameters
*/
mappIntelligenceHybrid.track(String rURL);isValidPixelRequest
Checks whether a query string is accepted by track: it must not be null, must contain the pixel parameter p with a value (p=...) and may be at most 64 KB (65,536 bytes, measured in UTF-8).
/**
* @param queryString Query string of the pixel request
*
* @return true if the query string contains the pixel parameter "p" and is not too long
*/
boolean valid = MappIntelligenceHybrid.isValidPixelRequest(String queryString);flush
Here you can explicitly tell to send the data to the Mapp tracking servers.
/**
*
*/
mappIntelligenceHybrid.flush();setOnFlushComplete
Here you can define a callback method that is automatically called after each flush. The first argument is the status of the request dispatch. The second argument specifies which queue was involved.
/**
* @param callback Callback for complete flushing
*/
mappIntelligenceHybrid.setOnFlushComplete(BiConsumer<Boolean, Integer> callback);close
Same as MappIntelligenceTracking.close(): sends the remaining requests, waits up to 30 seconds (one deadline for all queues) for them to be handed to the consumer, releases thread pools and file handles, and is idempotent. Use one instance per request with try-with-resources (see the example below).
/**
*
*/
mappIntelligenceHybrid.close();getUserIdCookie
Returns the same cookies as MappIntelligenceTracking.getUserIdCookie() (see the MappIntelligenceTracking tab), so a user without everID gets one. The generated everID is not added to the requests of the hybrid, because the requests forwarded from the pixel carry their own eid.
/**
* @param pixelVersion Version ot the current pixel (v4, v5, smart)
* @param context Cookie context (CLIENT_SIDE_COOKIE = "1", SERVER_SIDE_COOKIE = "3")
*
* @return MappIntelligenceCookie
*/
MappIntelligenceCookie mappCookie = mappIntelligenceHybrid.getUserIdCookie(String pixelVersion, String context);Note
getTransmittedCampaignsCookie()is also available onMappIntelligenceHybrid, but it always returnsnullthere: the hybrid forwards the pixel requests unchanged and does not evaluate campaigns.
getResponseAsString
As response, the method returns a 1x1px transparent gif, which you then returned to the client.
/**
* @return Returns a 1x1px transparent gif as string.
*/
String imageString = mappIntelligenceHybrid.getResponseAsString();Note
The string is created from the GIF bytes with the platform default charset, so it does not reliably contain the original bytes. To send the image to the client, use getResponseAsBytes.
getResponseAsBytes
As response, the method returns a 1x1px transparent gif, which you then returned to the client.
/**
* @return Returns a 1x1px transparent gif as byte array.
*/
byte[] imageBytes = mappIntelligenceHybrid.getResponseAsBytes();Example
package demo.servlets;
import com.mapp.intelligence.tracking.MappIntelligence;
import com.mapp.intelligence.tracking.MappIntelligenceCookie;
import com.mapp.intelligence.tracking.config.MappIntelligenceConfig;
import com.mapp.intelligence.tracking.core.MappIntelligenceHybrid;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
@WebServlet("/pix/*")
public class TrackingServlet extends HttpServlet {
public TrackingServlet() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// set tracking configuration
MappIntelligenceConfig mappConfig = new MappIntelligenceConfig()
.setTrackId("111111111111111")
.setTrackDomain("analytics01.wt-eu02.net")
.setReferrerURL(request.getHeader("Referer"))
// with the query string: the hybrid forwards the query parameters of the pixel request
.setRequestURL(request.getRequestURL() + (request.getQueryString() != null ? "?" + request.getQueryString() : ""))
.setRemoteAddress(request.getRemoteAddr())
.setUserAgent(request.getHeader("User-Agent"));
// read out all client cookies and add them to the configuration
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
mappConfig.addCookie(cookie.getName(), cookie.getValue());
}
}
// the instance carries the data of this request, so it is created and closed per request;
// close() sends the remaining requests
try (MappIntelligenceHybrid mappHybrid = new MappIntelligenceHybrid(mappConfig)) {
// writes the incoming request to the Mapp Intelligence request queue
mappHybrid.track();
byte[] imgBytes = mappHybrid.getResponseAsBytes();
// set content-type and length
response.setContentType("image/gif");
response.setContentLength(imgBytes.length);
// read out the existing Mapp Intelligence user cookie
MappIntelligenceCookie mappUserCookie = mappHybrid.getUserIdCookie(MappIntelligence.SMART, MappIntelligence.CLIENT_SIDE_COOKIE);
if (mappUserCookie != null) {
// create a cookie
Cookie mappUserCookieResponse = new Cookie(mappUserCookie.getName(), mappUserCookie.getValue());
mappUserCookieResponse.setHttpOnly(mappUserCookie.isHttpOnly());
mappUserCookieResponse.setSecure(mappUserCookie.isSecure());
// the v4 and smart pixel cookies have no domain (empty string)
if (!mappUserCookie.getDomain().isEmpty()) {
mappUserCookieResponse.setDomain(mappUserCookie.getDomain());
}
mappUserCookieResponse.setPath(mappUserCookie.getPath());
mappUserCookieResponse.setMaxAge(mappUserCookie.getMaxAge());
// add the cookie to the response
response.addCookie(mappUserCookieResponse);
}
// send a 1x1 pixel transparent gif back to the client, unchanged
OutputStream out = response.getOutputStream();
out.write(imgBytes);
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
}Further Classes
MappIntelligenceParameter
Package com.mapp.intelligence.tracking. Constants with the names of all request parameters, for example MappIntelligenceParameter.PAGE_NAME (pn) or MappIntelligenceParameter.ORDER_VALUE (ov). Use them with a MappIntelligenceParameterMap (see Request Parameters). In addition, the class contains the prefixes of the numbered custom parameters and the cookie names:
Name | Value | Description |
|---|---|---|
CUSTOM_SESSION_PARAMETER |
| Prefix of session parameters. |
CUSTOM_PAGE_PARAMETER |
| Prefix of page parameters. |
CUSTOM_PRODUCT_PARAMETER |
| Prefix of E-Commerce Parameters (product, order, goals). |
CUSTOM_ACTION_PARAMETER |
| Prefix of event parameters. |
CUSTOM_CAMPAIGN_PARAMETER |
| Prefix of campaign parameters. |
CUSTOM_REGISTRATION_PARAMETER |
| Prefix of the Mapp Engage registration parameters. |
CUSTOM_PAGE_CATEGORY |
| Prefix of page categories. |
CUSTOM_PRODUCT_CATEGORY |
| Prefix of product categories. |
CUSTOM_URM_CATEGORY |
| Prefix of user (URM) categories. |
SMART_PIXEL_COOKIE_NAME |
| everID cookie of the Smart Pixel. |
TRANSMITTED_CAMPAIGNS_COOKIE_NAME |
| Cookie with the campaigns already transmitted in this session. |
PIXEL_COOKIE_NAME |
| everID cookie of pixel v4/v5. |
SERVER_COOKIE_NAME_PREFIX |
| Prefix of the server-side everID cookie ( |
MappIntelligenceCustomParameter
Package com.mapp.intelligence.tracking. Enum to build the names of numbered custom parameters. The constants are CUSTOM_SESSION_PARAMETER, CUSTOM_PAGE_PARAMETER, CUSTOM_PRODUCT_PARAMETER, CUSTOM_ACTION_PARAMETER, CUSTOM_CAMPAIGN_PARAMETER, CUSTOM_REGISTRATION_PARAMETER, CUSTOM_PAGE_CATEGORY, CUSTOM_PRODUCT_CATEGORY, CUSTOM_URM_CATEGORY (prefixes as in the table above).
with
/**
* @param id ID of the custom parameter
*
* @return String e.g. "cp5" for CUSTOM_PAGE_PARAMETER.with(5)
*/
String name = MappIntelligenceCustomParameter.CUSTOM_PAGE_PARAMETER.with(int id);MappIntelligenceLogLevel
Package com.mapp.intelligence.tracking. Constants for MappIntelligenceConfig.setLogLevel(int): NONE = 0, FATAL = 1, ERROR = 2 (default), WARN = 3, INFO = 4, DEBUG = 5. A level shows all messages of that level and of the levels with a lower number.
getName
/**
* @param ll Integer log level
*
* @return Log level name, e.g. "ERROR", or null for an unknown value
*/
String name = MappIntelligenceLogLevel.getName(int ll);getValue
/**
* @param ll Log level name (case-insensitive)
*
* @return int Integer log level, -1 for an unknown name or null
*/
int value = MappIntelligenceLogLevel.getValue(String ll);AbstractMappIntelligenceData
Package com.mapp.intelligence.tracking.data. Base class of all data objects (MappIntelligencePage, MappIntelligenceAction, …). Its methods are useful for debugging.
getData
/**
* @return Map(String, Object) All fields of the data object, including unset ones
*/
Map<String, Object> data = mappPageData.getData();getQueryParameter
/**
* @return Map(String, String) The request parameters the object produces
*/
Map<String, String> queryParameter = mappPageData.getQueryParameter();For a campaign, getQueryParameter() contains only the explicitly set ID. The media codes of the request URL and once per session are resolved by track().
MappIntelligenceConsumerHttpClient and MappIntelligenceConsumerFile
Package com.mapp.intelligence.tracking.consumer. The built-in consumers for the consumer types HTTP_CLIENT and FILE (see Data Transfer: Consumer). The library creates them itself. Create one yourself only to extend it or to share one instance via setConsumer. A consumer that you create yourself has to be closed by you.
/**
* @param config Mapp Intelligence configuration, e.g. mappIntelligenceConfig.build()
*/
MappIntelligenceConsumerHttpClient httpConsumer = new MappIntelligenceConsumerHttpClient(Map<String, Object> config);
MappIntelligenceConsumerFile fileConsumer = new MappIntelligenceConsumerFile(Map<String, Object> config);setOnSessionId
MappIntelligenceConsumerHttpClient only. Optional callback that receives the ID of the TLS session the batch was sent over, after each batch. It is called from the queue threads, so it must be thread-safe.
/**
* @param callback Receiver of the TLS session ID
*/
httpConsumer.setOnSessionId(Consumer<byte[]> callback);