Interfaces

Prev Next

Methods

setDomain

/**
 * @param domain Specifies the domain within which this cookie should be presented.
 */
setDomain(domain: string) => void;

getDomain

/**
 * @return Gets the domain name of this cookie.
 */
getDomain() => string;

setMaxAge

/**
 * Sets the maximum age in seconds for this cookie.
 *
 * @param expiry Sets the maximum age in seconds for this cookie.
 */
setMaxAge(expiry: number) => void;

getMaxAge

/**
 * Gets the maximum age in seconds of this cookie.
 *
 * @return Gets the maximum age in seconds of this cookie.
 */
getMaxAge() => number;

Warning

The value is in seconds. Express (response.cookie()) expects maxAge in milliseconds: pass getMaxAge() * 1000, otherwise the everID cookie expires after about 4 hours instead of 6 months and every visitor is counted again and again. A value of -1 means a session cookie: do not pass maxAge at all.

setPath

/**
 * @param uri Specifies a path for the cookie to which the client should return the cookie.
 */
setPath(uri: string) => void;

getPath

/**
 * @return Returns the path on the server to which the browser returns this cookie.
 */
getPath() => string;

setSecure

/**
 * @param flag Indicates to the browser whether the cookie should only be sent using a secure protocol, such as
 *             HTTPS or SSL.
 */
setSecure(flag: boolean) => void;

isSecure

/**
 * @return  Returns true if the browser is sending cookies only over a secure protocol, or false if the browser
 *          can send cookies using any protocol.
 */
isSecure() => boolean;

getName

/**
 * @return Returns the name of the cookie.
 */
getName() => string;

getValue

/**
 * @return Gets the current value of this cookie.
 */
getValue() => string;

setHttpOnly

/**
 * @param isHttpOnly Marks or unmarks this cookie as HttpOnly.
 */
setHttpOnly(isHttpOnly: boolean) => void;

isHttpOnly

/**
 * @return Checks whether this cookie has been marked as HttpOnly.
 */
isHttpOnly() => boolean;

Create your own LoggerClass to debug our Mapp Intelligence js library.

Methods

log

/**
 * @param msg Debug message
 */
log(...msg: Array<any>) => void;

Example

class CustomLogger implements IMappIntelligenceLogger {
	public log(...msg: Array<any>): void {
		console.log(...msg);
	}
}

Create your own ConsumerClass to use for data transfer to Intelligence.

Methods

sendBatch

Required by the TypeScript interface, also for a consumer that implements send(). Resolves to true (SENT) or false (RETRY).

/**
 * @param batchContent List of tracking requests
 *
 * @return Promise<boolean>
 */
sendBatch(batchContent: Array<string>): Promise<boolean>;

send (optional)

Sends a batch and reports what happened to it: MappIntelligenceBatchResult.SENT, RETRY or DISCARDED (see Data Transfer: Consumer). If send() exists, the library calls it instead of sendBatch(); sendBatch() is still required by the TypeScript interface (it is not called then). A consumer that never discards a batch can keep implementing sendBatch() only: true means SENT, false means RETRY.

A consumer that throws or rejects, or resolves to anything else, is treated as RETRY: the batch stays in the queue and the error is logged. The library does not log a DISCARDED batch of a custom consumer: log the reason in your consumer, the flush only resolves to false.

/**
 * @param batchContent List of tracking requests
 *
 * @return Promise<string>
 */
send?(batchContent: Array<string>): Promise<string>;

close (optional)

Releases the resources of the consumer. The library only closes the consumers it created itself: a consumer that you pass in via setConsumer may be shared by several tracking instances, so closing it is up to you.

/**
 * @return Promise<void>
 */
close?(): Promise<void>;

Example

class TestCustomPrintConsumer implements IMappIntelligenceConsumer {
    public async sendBatch(batchContent: Array<string>): Promise<boolean> {
        for (const request of batchContent) {
            console.log(request);
        }

        return true;
    }
}

A consumer that can discard a batch implements send() as well:

class TestCustomDiscardingConsumer implements IMappIntelligenceConsumer {
    public async send(batchContent: Array<string>): Promise<string> {
        // implement custom consumer logic
        return MappIntelligenceBatchResult.SENT; // or RETRY, DISCARDED
    }

    public async sendBatch(batchContent: Array<string>): Promise<boolean> {
        return (await this.send(batchContent)) === MappIntelligenceBatchResult.SENT;
    }
}