Classes
    • 3 Minutes to read
    • Dark
      Light

    Classes

    • Dark
      Light

    Article summary

    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

    Sends the data to the Mapp track server. For a complete data configuration of the Mapp Intelligence Java library, please check Data.

    /**
     * @return boolean
     */
    mappIntelligence.track();
    /**
     * @param data Mapp Intelligence parameter map
     *
     * @return boolean
     */
    mappIntelligence.track(MappIntelligenceParameterMap data);
    /**
     * @param data Mapp Intelligence data map
     *
     * @return boolean
     */
    mappIntelligence.track(MappIntelligenceDataMap data);

    flush

    Here you can explicitly tell to send the data to the Mapp tracking servers. In most configurations this is done automatically by the Java runtime environment. Just to be sure, you should call this manually at the end of your script.

    /**
     * @return boolean
     */
    mappIntelligence.flush();

    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.

    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);

    Methods

    constructor

    For a complete configuration of the Mapp Intelligence Hybrid please check Configuration.

    /**
     * @param config Mapp Intelligence configuration
     */
    MappIntelligenceHybrid mappIntelligenceHybrid = new MappIntelligenceHybrid(MappIntelligenceConfig config);

    track

    Reads all query parameters from the current request URL and saves them in the file.

    mappIntelligenceHybrid.track();
    /**
     * @param rURL request url with query parameters
     */
    mappIntelligenceHybrid.track(String rURL);

    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();

    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.imageio.ImageIO;
    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.awt.image.BufferedImage;
    import java.io.ByteArrayInputStream;
    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"))
                .setRequestURL(request.getRequestURL().toString())
                .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());
                }
            }
    
            mappIntelligenceHybrid mappHybrid = new mappIntelligenceHybrid(mappConfig);
    
    		// writes the incoming request to the Mapp Intelligence request queue
            mappHybrid.track();
    
    		// set content-type and length
            response.setContentType("image/gif");
            response.setContentLength(43);
    
    		// read out the existing Mapp Intelligence user cookie
            MappIntelligenceCookie mappUserCookie = mappHybrid.getUserIdCookie(MappIntelligence.SMART, MappIntelligence.CLIENT_SIDE_COOKIE);
            if (mappUserCookie != null) {
    			// create an cookie
                Cookie mappUserCookieResponse = new Cookie(mappUserCookie.getName(), mappUserCookie.getValue());
                mappUserCookieResponse.setHttpOnly(mappUserCookie.isHttpOnly());
                mappUserCookieResponse.setSecure(mappUserCookie.isSecure());
                mappUserCookieResponse.setDomain(mappUserCookie.getDomain());
                mappUserCookieResponse.setPath(mappUserCookie.getPath());
                mappUserCookieResponse.setMaxAge(mappUserCookie.getMaxAge());
    
    			// add the cookie to the response
                response.addCookie(mappUserCookieResponse);
            }
    
    		// send an 1x1 pixel transparent gif back to the client
            byte[] imgBytes = mappHybrid.getResponseAsBytes();
            OutputStream out = response.getOutputStream();
            BufferedImage bufImg = ImageIO.read(new ByteArrayInputStream(imgBytes));
            ImageIO.write(bufImg, "gif", out);
        }
    
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            this.doGet(request, response);
        }
    }
    
    


    Was this article helpful?

    What's Next