Classes
    • 3 Minutes to read
    • Dark
      Light

    Classes

    • Dark
      Light

    Article summary

    Methods

    constructor

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

    /**
     * @param config Mapp Intelligence configuration
     */
    const mappIntelligence = new MappIntelligenceTracking(config: MappIntelligenceConfig);

    track

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

    /**
     * @param [data] Mapp Intelligence parameter or data map
     *
     * @return Promise<boolean>
     */
    mappIntelligence.track(data?: MappIntelligenceParameterMap | MappIntelligenceDataMap);

    flush

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

    /**
     * @return Promise<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 IMappIntelligenceCookie), which you then returned to the client.

    Options

    MappIntelligenceTracking.V4

    pixelVersion

    MappIntelligenceTracking.V5

    pixelVersion

    MappIntelligenceTracking.SMART

    pixelVersion

    MappIntelligenceTracking.CLIENT_SIDE_COOKIE

    context

    MappIntelligenceTracking.SERVER_SIDE_COOKIE

    context

    /**
     * @param pixelVersion Version ot the current pixel (v4, v5, smart)
     * @param context Cookie context (1, 3)
     *
     * @return IMappIntelligenceCookie
     */
    const mappCookie: IMappIntelligenceCookie = mappIntelligence.getUserIdCookie(pixelVersion: string, context: string);

    Methods

    constructor

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

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

    track

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

    /**
     * @param rURL request url with query parameters
     *
     * @return Promise<void>
     */
    mappIntelligenceHybrid.track();

    getResponseAsBase64

    As response, the method returns a 1x1px transparent gif, which you then returned to the client.

    /**
     * @return Returns a 1x1px transparent gif as base64 string.
     */
    const imageString = mappIntelligenceHybrid.getResponseAsBase64();

    getResponseAsBuffer

    As response, the method returns a 1x1px transparent gif, which you then returned to the client.

    /**
     * @return Returns a 1x1px transparent gif as buffer.
     */
    const imageBytes = mappIntelligenceHybrid.getResponseAsBuffer();

    Example

    import express from 'express';
    import bodyParser from 'body-parser';
    import cookieParser from 'cookie-parser';
    import {
        MappIntelligenceConfig,
        MappIntelligenceHybrid
    } from '@mapp-intelligence/node';
    
    import http from 'http';
    
    const app = express();
    app.use(bodyParser());
    app.use(cookieParser('secret'));
    
    app.use(function(request, response, next) {
        next();
    });
    
    app.get(/\/pix\/.*/, async function(request, response) {
        // set tracking configuration
        const mappConfig = new MappIntelligenceConfig()
            .setTrackId('111111111111111')
            .setTrackDomain('analytics01.wt-eu02.net')
            .setReferrerURL(request.headers['referer'])
            .setRequestURL('http://' + request.headers['host'] + request.url)
            .setRemoteAddress(request.headers['x-forwarded-for'] || request.socket.remoteAddress)
            .setUserAgent(request.headers['user-agent']);
    
        // read out all client cookies and add them to the configuration
        const cookies = request.cookies;
        if (cookies) {
            for (let cookie in cookies) {
                mappConfig.addCookie(cookie, cookies[cookie]);
            }
        }
    
        const mappHybrid = new MappIntelligenceHybrid(mappConfig);
    
        // writes the incoming request to the Mapp Intelligence request queue
        await mappHybrid.track();
    
        // read out the existing Mapp Intelligence user cookie
        const mappUserCookie = mappHybrid.getUserIdCookie(
            MappIntelligenceHybrid.SMART,
            MappIntelligenceHybrid.CLIENT_SIDE_COOKIE
        );
    
        if (mappUserCookie) {
            response.cookie(
                mappUserCookie.getName(),
                mappUserCookie.getValue(),
                {
                    domain: mappUserCookie.getDomain(),
                    path: mappUserCookie.getPath(),
                    secure: mappUserCookie.isSecure(),
                    maxAge: mappUserCookie.getMaxAge(),
                    httpOnly: mappUserCookie.isHttpOnly()
                }
            );
        }
    
        // set content-type and length
        response.writeHead(200, {
            'Content-Type': 'image/gif;charset=UTF-8',
            'Content-Length': '43'
        });
    
    	// send an 1x1 pixel transparent gif back to the client
        response.end(mappHybrid.getResponseAsBuffer(), 'binary');
    });
    
    http.createServer(app).listen(8090, '127.0.0.1', function() {
        console.log('Server listen on 127.0.0.1:8090');
    });
    
    


    Was this article helpful?

    What's Next