Skip to main content

Triggering the "Back-in-Stock Subscription" scenario

Description

The rrApi.subscribeOnItemBackInStock method subscribes a user to a back-in-stock notification scenario.

Before calling rrApi.subscribeOnItemBackInStock, call rrApi.setProfile with the user's email address so that the address is added to the Retail Rocket database.

The scenario can be triggered in two ways:

  1. The user subscribes to a product through rrApi.subscribeOnItemBackInStock.
  2. The user visits an out-of-stock product page. In this case, the subscription is created automatically after the product card view method is triggered.

The email is sent after the product parameter changes from available="false" to available="true".

By default, the subscription is stored for 7 calendar days. You can change the storage period by contacting Retail Rocket technical support.

Code example

<script type="text/javascript">
(window.rrApiOnReady = window.rrApiOnReady || []).push(function() {
try {
rrApi.setProfile({
"email": "example@example.com",
"isAgreedToReceiveMarketingMail": true
});
rrApi.subscribeOnItemBackInStock("example@example.com", 12345);
} catch (e) {}
});
</script>

Triggering without passing an email address

Use the rrApi.subscribeOnItemBackInStockV2 method when you do not need to pass an email address in the call. Retail Rocket looks up the email address associated with the user's cookie if the user has previously provided an email address and it is associated with the current visitor.

<script type="text/javascript">
(window.rrApiOnReady = window.rrApiOnReady || []).push(function() {
try {
rrApi.subscribeOnItemBackInStockV2(12345);
} catch (e) {}
});
</script>