Events based integration

Discount Ninja publishes events that you can hook in to. This allows you to add logic after specific events occur.

You can also publish events to inform Discount ninja about changes on the web page.

Available integration points

Promotions

Event: limoniapps:discountninja:promotions:loaded
Timing: this event is triggered by the app after promotions have been loaded and processed by the app
Parameters:

  • event.detail.data: an array of objects representing the offers loaded by the app 

Usage

document.addEventListener("limoniapps:discountninja:promotions:loaded", function (event) { console.log('Promotions loaded', event.detail.data); [... your logic here ...] });

Object structure:

A promotion object contains:

  • Token: the token of the offer

  • TriggeredByTrigger: the trigger that triggered the offer, including its token (TriggeredByTrigger.Token), the Schedule, the Filter settings and an array of offer tokens in Offers.

  • Entitlement: describes what the offer includes

  • Tiers: describes further details of the offer per tier

  • Prerequisite: describes what needs to be in the cart for the offer to apply

  • Stacking: contains information about if/how the offer stacks and combines with other offers

  • Building blocks: the Notification, StickyBar, Cart and DrawerCart properties describe the configuration of the building blocks for the offer

Cart

Event: limoniapps:discountninja:cart:updated
Timing: this event is triggered by the app after an update to the cart has been processed
Parameters:

  • event.detail.data[0] an object representing the cart with discounts applied

Usage:

document.addEventListener("limoniapps:discountninja:cart:updated", function (event) { let cart = event.detail.data[0]; console.log('Cart updated', cart); [... your logic here ...] });

Object structure:

  • CartLevelDiscounts: an array of discounts applied at cart level

  • items: an array of line items that are present in the cart (linked to the Shopify cart using the Key) that includes information about the applied offer and trigger (OfferToken and TriggerToken) as well as information about the product (Product) and the line (Line) as well as the Properties applied to the line

  • total_discount: total amount of the discount

  • total_discounted_price: subtotal of the cart including discounts

  • total_original_price: subtotal of the cart excluding discounts

Checkout

Event: limoniapps:discountninja:checkout:initiate
Timing: trigger this event to instruct Discount Ninja to initiate a checkout
Parameters: N/A

Usage:

document.dispatchEvent(new CustomEvent('limoniapps:discountninja:checkout:initiate'));

Alternatively, to trigger the event only when a Discount Ninja checkout is required:

if (typeof discountNinja !== 'undefined' && discountNinja.Checkout.Shopify.RequiresAdvancedCheckout()) {
document.dispatchEvent(new CustomEvent('limoniapps:discountninja:checkout:initiate'));
}

Event: limoniapps:discountninja:stickybar:closed
Timing: this event is triggered by the app when the stickybar is closed
Parameters: N/A

Usage:

document.addEventListener("limoniapps:discountninja:stickybar:closed", function (event) { console.log('Sticky bar closed'); [... your logic here ...] });

Notification

Event: limoniapps:discountninja:notification:closed
Timing: this event is triggered by the app when the notification is closed
Parameters: N/A

Usage:

document.addEventListener("limoniapps:discountninja:notification:closed", function (event) { console.log('Notification closed'); [... your logic here ...] });

Event: limoniapps:discountninja:notification:minimized
Timing: this event is triggered by the app when the notification is minimized
Parameters: N/A

Usage:

document.addEventListener("limoniapps:discountninja:notification:minimized", function (event) { console.log('Notification minimized'); [... your logic here ...] });

Event: limoniapps:discountninja:notification:maximized
Timing: this event is triggered by the app when the notification is maximized
Parameters: N/A

Usage:

document.addEventListener("limoniapps:discountninja:notification:maximized", function (event) { console.log('Notification maximized'); [... your logic here ...] });

Drawer cart

Event: limoniapps:discountninja:drawercart:opened
Timing: trigger this event when the drawer cart has been opened or updated; this allows the app to ensure the correct discounted prices are displayed in the drawer cart
Parameters: N/A

Usage:

document.dispatchEvent(new CustomEvent('limoniapps:discountninja:drawercart:opened'));

Event: limoniapps:discountninja:drawercart:refreshed
Timing: this event is triggered by the app after an update to the cart has been processed that should be reflected in the drawer cart; this event should be handled by the theme and should result in redrawing the drawer cart based on the cart provided
Parameters:

  • event.detail.data[0] an object representing the cart

Usage:

document.addEventListener("limoniapps:discountninja:drawercart:refreshed", function (event) { let cart = event.detail.data[0]; console.log('Cart updated', cart); [... your logic here ...] });

Collection products

Event: limoniapps:discountninja:collection:productsadded
Timing: trigger this event when additional products are added dynamically to the collection page (e.g. infinite scroll) to ensure the correct discounted prices are displayed on the collection page
Parameters: N/A

Usage:

document.dispatchEvent(new CustomEvent('limoniapps:discountninja:collection:productsadded')); 

Variant

Event: limoniapps:discountninja:variant:changed
Timing: trigger this event when a different variant is selected on the product pages; this event is only required if the standard mechanisms included in the app fail to detect when variants are changed automatically
Parameters: pass the variant id as a number

{ detail: { variant: add_the_variant_id_as_a_number } }

Usage:

document.dispatchEvent(new CustomEvent('limoniapps:discountninja:variant:changed', { detail: { variant: add_the_variant_id_as_a_number } })); 

Trigger promotions programmatically

Promotions can be triggered programmatically via the trigger token.

Use the following command to trigger a promotion with the token ABCD.

Usage:

discountNinja.Core.TriggerPromotionViaToken('ABCD');

Alternatively, you can create a button or link that can be used to trigger the promotion automatically once the element is clicked.

To do so:

  • Add the class limoniapps-discountninja-discountbutton to the element

  • Add the attribute data-limoniapps-discountninja-token to the element and set it to the token of the promotion

Bypass checkout

By default, Discount Ninja attaches to the click event of checkout buttons. When a promotion is active the app will create a discounted checkout and direct the visitor to this checkout.

There may be situations, specifically when integrating apps with Discount Ninja, where you need to bypass Discount Ninja's handling of the checkout. To do this, add the following class to the checkout button:

limoniapps-discountninja-ignore

Disable/re-enable the app

To manually disable the app during a web session:

document.dispatchEvent(new CustomEvent('limoniapps:discountninja:app:disable')); 

To manually re-enable the app during a web session:

document.dispatchEvent(new CustomEvent('limoniapps:discountninja:app:enable')); 

Did this answer your question?