Skip to main content

Get Customer's Streak Count and Display It

In this example you'll get the number of consecutive subscription-related charges processed for a customer.

Pre-requisites

  • You have a Shopify store.
  • You have access to Rewards in your Recharge account. (See Rewards)
  • You have a customer with an active subscription.
  • You have basic knowledge of HTML and JavaScript.

Explanation

In this example we will retrieve the customer's subscription_related_charge_streak and display it inside a span HTML element. See subscription_related_charge_streak for a more detailed description of this attribute.

Example Code

Methods and Types:

<button id="get-streak-count-btn">Get Customer Streak Count</button>
<p>Customer streak count: <span id="streak-count-value"></span></p>

<script>
document.getElementById('get-streak-count-btn').addEventListener('click', async () => {
const session = await getSession();

const customer = await recharge.customer.getCustomer(session);

document.getElementById('streak-count-value').innerText = customer.subscription_related_charge_streak;
});
</script>