> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aftersell.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Common use cases

> Complete, runnable Aftersell Cart SDK solutions to the things merchants ask for most: analytics tracking, free gifts, hiding lines, metafields, bundles, and page builders.

Complete solutions to the requests that come up most often. Each one is a runnable snippet with a walkthrough and notes on adapting it.

## Before you write a script

A lot of what merchants used to script is now a built-in setting. Check this first, because a setting keeps working through cart redesigns and your script might not:

| If you want to…                                         | Use this instead of code                                                                                                                                                |
| ------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Open the drawer whenever an item is added               | **Cart settings → Content → Behavior → Open cart when an item is added**                                                                                                |
| Keep your theme's cart icon count in sync               | Built in. Set **cart count selector** in cart settings if your theme needs a nudge.                                                                                     |
| Show different settings by country, market, or currency | [Conditions](/aftersell/cart/blocks-overview#show-or-hide-by-market-country-or-currency) (full UI on [Rewards](/aftersell/cart/rewards-block#per-market-rewards) today) |
| Offer a free gift at a spend threshold                  | The [Rewards](/aftersell/cart/rewards-block) block                                                                                                                      |
| Add an upsell, add-on, or shipping protection           | The matching [cart block](/aftersell/cart/blocks-overview)                                                                                                              |
| Restyle anything                                        | [Design settings](/aftersell/cart/design-settings), then [Custom CSS](/aftersell/cart/custom-css)                                                                       |

Reach for the SDK when the logic is genuinely yours: a rule no setting expresses, an integration with another app, or data only your store has.

## How to use these

Paste a snippet into your cart's **Initialization** script. In the cart editor, go to **Cart settings → Custom script → Initialization**. Write plain JavaScript; no `<script>` tags. See [Custom scripts](/aftersell/cart/custom-scripts) for the details.

## The use cases

<Columns cols={2}>
  <Card title="Track add-to-cart in a third-party tool" icon="chart-line" href="/aftersell/cart/sdk-use-case-analytics">
    Send cart events to Klaviyo, Triple Whale, GA4, or any analytics pixel.
  </Card>

  <Card title="Auto-add a free gift at a threshold" icon="gift" href="/aftersell/cart/sdk-use-case-free-gift">
    Add a gift when the total crosses a threshold, remove it when it drops back.
  </Card>

  <Card title="Hide and relabel cart lines" icon="eye-slash" href="/aftersell/cart/sdk-use-case-hide-lines">
    Hide app-injected or free lines, rename them, and control their order.
  </Card>

  <Card title="Show metafield data on cart lines" icon="tags" href="/aftersell/cart/sdk-use-case-metafields">
    Pull a delivery estimate, badge, or any metafield onto every line.
  </Card>

  <Card title="Open the drawer from a page builder" icon="wand-magic-sparkles" href="/aftersell/cart/sdk-use-case-page-builder">
    Make Replo, PageFly, GemPages, and custom buttons open the cart.
  </Card>

  <Card title="Require terms before checkout" icon="square-check" href="/aftersell/cart/sdk-use-case-terms-checkbox">
    Block checkout until the shopper accepts your terms.
  </Card>

  <Card title="Group bundle lines from another app" icon="boxes-stacked" href="/aftersell/cart/sdk-use-case-bundles">
    Make a bundle app's separate cart lines render as one item.
  </Card>
</Columns>
