Options
All
  • Public
  • Public/Protected
  • All
Menu

Contains utility methods that may be useful for consumers of the patch collector.

esm

import { utils } from '@paychex/collector-batch';

cjs

const { utils } = require('@paychex/collector-batch');

amd

define(['@paychex/collector-batch'], function({ utils }) { ... });
require(['@paychex/collector-batch'], function({ utils }) { ... });

iife

const { utils } = window['@paychex/collector-batch'];

Index

Type aliases

Functions

Type aliases

PatchResult: [TrackingInfo?, ...Operation[][]]

Functions

  • Converts an Array of TrackingInfo instances into an array whose first item is a TrackingInfo instance, and whose subsequent items are arrays of JSON-Patch operations.

    For example, if you set up your collector like this:

    import { batch, utils } from '@paychex/collector-batch';

    async function send(payload) {
    // payload will either be empty,
    // have a single TrackingInfo entry,
    // or have a TrackingInfo entry followed
    // by 1 or more arrays of JSON-Patch
    // operations describing the differences
    // from the previous payload entry
    }

    const collector = batch(send, utils.toPatch);

    And you sent the following events:

    tracker.event('click', { category: 'ux' });
    tracker.event('click', { category: 'menu', text: 'log out' });

    Then the payload provided to your send method would look like this:

    [
    {
    "id": "a0ed9697-1e38-4bca-b17b-5c79b9f028e2",
    "type": "event",
    "label": "click",
    "start": 1611604974339,
    "stop": 1611604974339,
    "duration": 0,
    "count": 1,
    "data": {
    "category": "ux"
    }
    },
    [
    {
    "op": "replace",
    "path": "/data/category",
    "value": "menu"
    },
    {
    "op": "add",
    "path": "/data/text",
    "value": "log out"
    },
    {
    "op": "replace",
    "path": "/stop",
    "value": 1611604974340
    },
    {
    "op": "replace",
    "path": "/start",
    "value": 1611604974340
    },
    {
    "op": "replace",
    "path": "/id",
    "value": "b387d125-1910-45ff-a346-cd17e35c9e94"
    }
    ]
    ]

    Parameters

    • entries: TrackingInfo[]

      The array of TrackingInfo instances to convert.

    Returns PatchResult

    An array of entries, where the first item is an unmodified TrackingInfo instance, and each subsequent item in the array is an Array of JSON-Patch operations.