Sleek’s SDK automatically classifies the pages your users are visiting. To setup this experience for your users, you’ll need to provide Sleek with the pages that you want to classify. This documentation will guide you through the integration process.

This document assumes that you have already integrated the Sleek SDK into your extension. If you haven’t, please refer to the SDK integration guide.

Enable page classification

After Sleek is installed and setup in your extension, you are ready to enable page classification.

Automatically classify pages

To automatically classify pages, set featureControls.emitPageClassification to true in the SDK’s options during initialization.

import { initializeSleekSdk } from "@sleek/web-ext-coupon-sdk";

// In your background script constructor or setup.
initializeSleekSdk(process.env.YOUR_SLEEK_CLIENT_API_KEY_HERE, {
  // Your options here.
  featureControls: {
    emitPageClassification: true,
  },
});

Now that you have enabled page classification, Sleek will automatically classify the pages your users are visiting. You can subscribe to the PAGE_CLASSIFIED event to be notified when a page has been classified.

Register for page classification events

Sleek’s SDK automatically emits events when pages are classified. Subscribe to the PAGE_CLASSIFIED event to be notified when a page has been classified.

For example, you might want to show different UI based on what type of page the user is viewing. To do so, you can follow a pattern like:

import { getSdkInstance, EventType } from "@sleek/web-ext-coupon-sdk";

getSdkInstance().registerEventListener((event, tabId) => {
  // `event` is typed, so the data of the event `event.data` is also typed
  // based on the type of the event.
  switch (event.type) {
    case EventType.PAGE_CLASSIFIED:
      // Do something with the page classification.
      console.log(event.data.classification);
      if (event.data.classification === "productDetailPage") {
        // Show product detail page UI.
      } else if (event.data.classification === "cart") {
        // Show cart page UI.
      }
      break;
  }
});

Manually classify pages

In addition to automatic emission of page class, you can manually classify a page by calling the classifyPageOnTab method.

import { getSdkInstance } from "@sleek/web-ext-coupon-sdk";

getSdkInstance().classifyPageOnTab(tabId); // Returns Promise<PageClassification | undefined>.

What’s next:

Now that you have enabled page classification in your extension, you can check out the TypeDoc for specific event types and methods on the SDK.

View TypeDoc

Browse the reference TypeDoc for the SDK.