0.1.0 • Published 4 years ago

dooh-instant-campaign-amplifier-plugin v0.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

DOOH-INSTANT-CAMPAIGN-AMPLIFIER-PLUGIN

NPM VERSION

A custom Amplifier plugin for DOOH Instant Campaign Launcher.

Available as NPM package.

What does it do?

Provide a plugin for updating an LemonPI product selector with the active product by it's SKU.

An example usage:

const { default: Amplifier, Variable Service } = require('@ghg/amplifier');

new Amplifier({
  name: 'my-dooh-instant-campaign-amplified',
  version: '1.0.0',
  requirements: [
    new Variable({
      name: 'tempNL',
      plugin: 'Weather',
      type: 'temperature',
    }),

    new Service({
      name: 'instantCampaign',
      plugin: 'DoohInstantCampaign',
      username: process.env.LEMONPI_USERNAME,
      password: process.env.LEMONPI_PASSWORD,
      advertiserId: process.env.LEMONPI_ADVERTISER_ID,
    }),
  ],
  rules: [
    {
      name: 'Activate my instant campaign, because the temperature is above 25 degrees',
      condition(R, { variables }) {
        R.when(variables.tempNL >= 25);
      },
      async consequence(R, { services }) {
        const productSKU = process.env.GOOD_WEATHER_PRODUCT_SKU;
        const productSelectorId = process.env.PRODUCT_SELECTOR_ID;

        await services.instantCampaign.setActiveSKU(productSKU, productSelectorId);
      }
    },
    {
      name: 'Deactivate my instant campaign, because the temperature is below 25 degrees',
      condition(R, { variables }) {
        R.when(variables.tempNL < 25);
      },
      async consequence(R, { services }) {
        const productSKU = process.env.BAD_WEATHER_PRODUCT_SKU;
        const productSelectorId = process.env.PRODUCT_SELECTOR_ID;

        await services.instantCampaign.setActiveSKU(productSKU, productSelectorId);
      }
    },
  ]
});

It can find the activate campaings as well:

const { default: Amplifier, Variable Service } = require('@ghg/amplifier');

const DOOH_INSTANT_CAMPAIGN_DEFAULTS = {
  plugin: 'DoohInstantCampaign',
  username: process.env.LEMONPI_USERNAME,
  password: process.env.LEMONPI_PASSWORD,
  advertiserId: process.env.LEMONPI_ADVERTISER_ID,
  sheetId: process.env.GOOGLE_SHEET_ID,
};

const PRODUCT_SELECTOR_ID = process.env.PRODUCT_SELECTOR_ID;

const MY_FALLBACK_PRODUCT_SKU = 12345;

new Amplifier({
  name: 'my-dooh-instant-campaign-amplified',
  version: '1.0.0',
  requirements: [
    new Variable({
      name: 'tempNL',
      plugin: 'Weather',
      type: 'temperature',
    }),

    new Variable({
      name: 'goodWeatherCampaigns',
      ...DOOH_INSTANT_CAMPAIGN_DEFAULTS,
      type: 'getActiveCampaigns',
      range: 'Blad1',
    }),

    new Service({
      name: 'instantCampaign',
      ...DOOH_INSTANT_CAMPAIGN_DEFAULTS,
    }),
  ],
  rules: [
    {
      name: 'Activate my instant campaign, because the temperature is above 25 degrees',
      condition(R, { variables }) {
        R.when(variables.tempNL >= 25 && variables.goodWeatherCampaigns.length > 0);
      },
      async consequence(R, { services, variables }) {
        // activate the first good weather campaign
        const { productSKU } = variables.goodWeatherCampaigns[0];

        await services.instantCampaign.setActiveSKU(productSKU, PRODUCT_SELECTOR_ID);
      }
    },
    {
      name: 'Deactivate my instant campaign, because the temperature is below 25 degrees',
      condition(R, { variables }) {
        R.when(variables.tempNL < 25 || variables.goodWeatherCampaigns.length <= 0);
      },
      async consequence(R, { services }) {
        // fallback to the bad weather campaign
        await services.instantCampaign.setActiveSKU(MY_FALLBACK_PRODUCT_SKU, PRODUCT_SELECTOR_ID);
      }
    },
  ]
});
0.1.0

4 years ago