Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Latest commit

 

History

History
87 lines (73 loc) · 2.47 KB

features.md

File metadata and controls

87 lines (73 loc) · 2.47 KB

EdgeKit | Page Features

A page feature is a value that describes a pages content. The features can be something concrete like a list of keywords on a page, or something more abstract like a vector.

EdgeKit requires pageFeatureGetters to be passed into the run method that will allow EdgeKit to evaluate the page. A page feature getter is an object that has a name and and an async function that resolves to a result. The result is an object in the form of:

type PageFeatureResult = {
  version: number;
  value: PageFeatureValue;
};

The version of the page feature is there to provide a mechanism for versioning page features and audience definitions that should match on them. See the audiences section and Edgekit's exported types for more details.

Example

The following is a working example of a pageFeatureGetter that gets the meta data keywords from the head of the HTML:

const getHtmlKeywords = {
  name: 'keywords',
  func: (): Promise<PageFeatureResult> => {
    const tag = <HTMLElement>(
      document.head.querySelector('meta[name="keywords"]')
    );
    const keywordString = tag.getAttribute('content') || '';
    const keywords = keywordString.toLowerCase().split(',');
    return Promise.resolve({
      version: 1, // Provide a version for your features
      value: keywords
    });
  },
};

If this getHtmlKeywords feature getter is passed to Edgekit with a page that looks like this:

<html>
  <head>
    <meta name="keywords" content="goal,liverpool,football,stadium" />
    ...
  </head>
  <body>
    ...
  </body>
</html>

Then Edgekit will store this feature, and any other features that were provided, in local storage as a page view along with the version it received:

> JSON.parse(localStorage.getItem('edkt_page_views'))
[
  {
    "ts": 1600858202179,
    "features": {
      "keywords": {
        "version": 1,
        "value": [
          "goal",
          "liverpool",
          "football",
          "stadium"
        ]
      }
    }
  }
]

The name that was provided in the page feature getter definition is the key where it will be stored in the features object (in this case keywords).

The audience definitions that are passed into Edgekit define whether or not the page views match the audience. If any of the audiences match then they will also get stored in local storage. Learn more about audiences