Learn why Gartner just named Builder a Cool Vendor

Announcing Visual Copilot - Figma to production in half the time

Builder.io logo
Contact Sales
Platform
Developers
Contact Sales

Blog

Home

Resources

Blog

Forum

Github

Login

Signup

×

Visual CMS

Drag-and-drop visual editor and headless CMS for any tech stack

Theme Studio for Shopify

Build and optimize your Shopify-hosted storefront, no coding required

Resources

Blog

Get StartedLogin

You can target content based on user interactions with your e-commerce platform's resources—such as products or collections—with e-commerce plugins.

To use e-commerce resource targeting, your app must pass the appropriate targeting attributes to Builder. For example, if you target an announcement bar to display when a user adds a certain item to their cart, your app must pass the product's id when requesting the announcement bar's content.

You can pass targeting attributes either by using the JavaScript SDK or with query string parameters when requesting content using the Builder Content API and GraphQL API.

The e-commerce custom type that you use for your targeting condition determines which targeting attribute you use. For example, when using a request object type like ShopifyProduct—displayed in the custom types list as Shopify Product when creating a new targeting condition—you must pass the Shopify ID for your product to the product attribute.

You can implement the above with the following code when using the SDK:

const content = await builder.get('myTargetedContent', {
  userAttributes: { product: product.id }
}).promise();

You can alternatively use setUserAttributes to set the targeting attributes once across multiple content requests:

builder.setUserAttributes({ product: product.id });

const content = await builder.get('myTargetedContent').promise();
const otherContent = await builder.get('myOtherTargetedContent').promise();

You can also pass the targeting attributes using query strings when you send requests with the content or GraphQL APIs:

const response = await fetch(`https://cdn.builder.io/api/v2/content/my-model?apiKey=YOUR_API_KEY&userAttributes.product=${product.id}`)

If product.id matches the ID of the product selected for your targeting condition, then your content renders.

After setting up your codebase to pass targeting attributes to Builder, you can target content using e-commerce targeting conditions. For example, you can show users an announcement bar when a certain product is in the cart.

To learn how to set up targeting within the Visual Editor, see Targeting with e-commerce plugins.

For more information on how to use e-commerce plugins, check out the following articles:

Was this article helpful?

Product

Visual CMS

Theme Studio for Shopify

Sign up

Login

Featured Integrations

React

Angular

Next.js

Gatsby

Get In Touch

Chat With Us

Twitter

Linkedin

Careers

© 2020 Builder.io, Inc.

Security

Privacy Policy

Terms of Service

Get the latest from Builder.io

By submitting, you agree to our Privacy Policy

Product

Platform Overview

Integrations

What's New

Open Source

Builder

Mitosis

AI Shell

Micro Agent

GPT Crawler

Qwik

Partytown

Popular Guides

From Design to Code Guide

Composable Commerce Guide

Headless CMS Guide

Headless Commerce Guide

Composable DXP Guide

Design to Code

Resources

Blog

Knowledge Base

Community Forum

Partners

Templates

Success Stories

Showcase

Resource Center

Frameworks

React

Next.js

Qwik

Gatsby

Angular

Vue

Svelte

Remix

Nuxt

Hydrogen

See All

© 2024 Builder.io, Inc.

Security

Privacy Policy

SaaS Terms

Security & Compliance

Cookie Preferences

Gartner Cool Vendor 2024