loveful.js) is loaded by the Loveful app embed with defer. It reads the page’s state from the HTML the embed prints, exposes a small bus on window.loveful, and defines the web components.
The global is always lowercase:
window.loveful. It exists only while the app embed is on.Waiting for the bus
Loveful firesloveful:ready on document once the bus is set up and, for a shopper who has just signed in, their guest items have moved to their account. Your script may load before or after Loveful’s, so check for the bus first and listen for the event otherwise:
loveful.ready resolves once a shopper who has just signed in has had their guest items moved to their account. For guests it resolves straight away. The examples below assume const loveful = window.loveful inside such a callback.
Properties
LovefulSnapshot
The shape of a saved item insnapshots and in item_added events:
state but not in snapshots: their details were rendered by Liquid, not sent to the script.
Methods
productSaved
snapshot
The saved item’s snapshot, or
null when the page has none for it. Accepts a string or number.clear
Empties one of the shopper’s lists.
options.list is the list number, 1 (the default list, and a guest’s only one) to 10. Resolves false when the request fails, or when a guest asks for a list other than 1. Clearing list 1 fires item_removed for each item, then one list_cleared.t
%count%, %title% or %email% in the defaults, or {{ count }} and the like in the merchant’s overrides:
publishAnalytics
Publishes a custom event to Shopify’s customer events (
Shopify.analytics.publish), for custom pixels to subscribe to. Does nothing where that API is unavailable.Share API
Each method calls Loveful through the store’s app proxy.getToken, resetToken and email need a signed-in shopper; getList works for anyone.
share_url is built on the shopper’s current domain and language root, with the token in the loveful_token query parameter.
share.getToken
The default list’s share link, made on first use. Rejects when the request fails.
share.resetToken
A new share link. The old one stops working. Rejects when the request fails.
share.getList
A shared list by its token. Rejects with
loveful.share.getList: not_found when the token is unknown or was reset.share.email
Emails the wishlist to one address, in the shopper’s language. Never rejects.
<loveful-share-link>’s email form shows each one in the merchant’s words: loveful.share_email_limit_recipient, loveful.share_email_limit, loveful.share_email_off and loveful.share_email_failed.
Bus events
window.loveful is an EventTarget. It dispatches CustomEvents whenever the saved state changes, in this tab or in another tab of the same store (changes are relayed between tabs with a BroadcastChannel named loveful). tab_id is the tab the change was made in: compare it with loveful.tabId to tell local changes from relayed ones.
item_added
A variant was saved.
state, snapshots and productOf are already updated.item_removed
A variant was removed. Also fired for each item when the default list is cleared.
list_cleared
The default list was emptied, after an
item_removed for each of variant_ids.Document events
loveful:ready
Fired ondocument once, with detail: { loveful }. See Waiting for the bus.
Share events
<loveful-share-link> dispatches bubbling CustomEvents on itself, so they can be caught on document:
Events Loveful listens for
The save button and the saved count follow the theme’s variant picker. They listen ondocument for:
shopify:product:select, Shopify’s standard storefront event: the variant comes from the event’spromise, which resolves with{ variant }.variant:update,variant:changeandchange: the variant id is read fromevent.detail.variant.idorevent.detail.resource.id(a GID or a number), or else from the?variant=URL parameter a tick later.
Shopify customer events
Loveful publishes these throughShopify.analytics.publish, so a custom pixel can subscribe to them. They are published only in the tab where the change was made.
Custom pixel
Data attributes on cards
Wishlist cards (li.loveful-card) carry data-variant-id and data-handle. While a card’s options are being changed it also carries data-swap-to with the new variant id.
Storage
Opening a shared wishlist with items sets the hidden cart attribute
_loveful_share to the share token (or <token>:<send id> when opened from a share email), so an order can be traced back to the share.