1.0.2 • Published 5 months ago

@evolv-delivery/audience v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

Audience

The audience integration supports populating the Evolv context object with values that are extracted from the browser via several mechanisms.

Note: This package will no longer be supported

Please use @evolv-delivery/metrics instead. The metrics package includes all the features as the audience package and represents the future direction for this integration.

Setup in the Evolv Manager

Adding an integration to the Evolv Manager

Setting up the config json

The main requirements for the config are objects indexed by a context attribute where the objects contain source and key.

Top Level Structure

The top level keys of the json config indicate one of two things and both have object values.

  • The attribute key (to use in context) if the object value contains a source and key field that have string values.
  • A top level grouping if the object does not contain a source and key field. This will results in each attribute of the object representing a context attribute.

Context attribute objects

The following is a table showing the different types for the attributes:

SourceKey (usage)Description
queryname of query parameterThe value of the query parameter within th url
expressionjs expressionThe experssion usually
cookiecookie nameReturn value of cookie
localStoragelocalStorage keyReturn value of localStorage key
sessionStoragesessionStorage keyReturn value of sessionStorage key
domcss selectorReturns found if dom element exists on page
jqdomjqery selectorReturns found if dom element exists on page
extensionname of extensionCurrenty only one extension distribution: tracks a random value between 0-100 that persists for user
fetchurlThis also includes additional data

Other attribute options

page

If a page is specified, it's value represents a regex on the current url that if specified, the attribute will only be evaluated upon the page matching. This helps to focus page specific attributes that may be slow in retrieval.

type

If a type attribute is specified, it's value represents the type of the value of the attribute. By default, the type is assumed to be string. The following are the types available:

  • boolean
  • float
  • int
  • string
  • array

map

The map is represented as an array of objects that allows the value of the attribute to be transformed. Those mappings have one of 3 json keys:

  • when - a regex for testing the attribute value against
  • result - the new value to be bound to the attribute when conditional is met
  • default - default can be used as result as the last map value. There should be no when value for default.

storage

The storage is an object indicating that the value should be cached with the following options:

  • key - a required key that indicates the key to store and retrieve from storage (The integration will prefix this key with evolv: )
  • type - (local|session) indicating localStorage or sessionStorage (defaults to session)
  • resolveWith - (new|cached|union) indicates how to resolve which value to use when there is both a new value and a cached value. (defaults to new)

spa

If the spa value is set to true, the attribute will be reevaluated upon any spa based navigation.

poll

If a value is not imediately available when the integration is processed, a poll can be specified to periodically reevaluate the attribute until it is detected or poll duration expires.

default

This allows a value to be specified that will be added to the context imediately if the attribute is not available yet. It will be overriden if the poll is set and the value becomes available.

The config is read top to bottom. If a match is found, it stops. No fall-through, so in the example below if the path of the page starts with /home/, nothing will happen, because the statements block is an empty array.

Example

The following shows examples of each of the type and options available.

{
    "ctas": {
        "placeOrder": {
            "page": "sales/digital/expressCheckout",
            "source": "dom",
            "key": "button[aria-label*='Place order']",
            "poll": {
                "interval": 100,
                "duration": 5000
            }
        }
    },
    "omni": {
        "visitorId": {
            "source": "expression",
            "key": "window._satellite.getVisitorId()._fields.MCMID"
        }
    },
    "recognizedUser": {
        "source": "cookie",
        "key": "user",
        "type": "boolean",
        "default": false,
        "map": [
            {
                "result": true,
                "when": ".+"
            }
        ]
    },
    "campaign": {
        "source": {
            "source": "query",
            "key": "utm_source"
        },
        "medium": {
            "source": "query",
            "key": "utm_medium"
        }
    },
    "page": {
            "landingTag": {
                "source": "expression",
                "key": "location.pathname",
                "default": "none",
                "storage": {
                    "type": "session",
                    "key": "landingTag",
                    "resolveWith": "cached"
                },
                "map": [
                {
                    "result": "products",
                    "when": "/products/"
                }
                ]
            }
    }
}
1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

10 months ago

0.8.5

1 year ago

0.8.4

1 year ago

0.9.0

1 year ago

0.9.2

1 year ago

0.8.3

1 year ago

0.9.1

1 year ago

0.8.1

1 year ago

0.8.0

1 year ago

0.8.2

1 year ago

0.5.4

1 year ago

0.5.3

1 year ago

0.5.0

1 year ago

0.7.0

1 year ago

0.5.2

1 year ago

0.6.0

1 year ago

0.5.1

1 year ago

0.3.0

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.3

1 year ago

0.2.1

2 years ago

0.1.0

2 years ago