Shopify カスタム統合設定
このページでは、カスタムストアフロントを使用して、Shopify Hydrogen ストアやヘッドレス Shopify ストアとBrazeを統合する方法を説明します。
このガイドでは、Shopifyの Hydrogen フレームワークを例にしています。ただし、ブランドが「ヘッドレス」フロントエンド設定でストアのバックエンドに Shopify を使用している場合も、同様のアプローチをとることができます。
Shopify のヘッドレスストアをBrazeと統合するには、以下の2つの目標を達成する必要があります。
- Braze Web SDKを初期化してロードし、オンサイトトラッキングを有効にする
手動で Shopify Webサイトにコードを追加して、Brazeオンサイトトラッキングを有効にします。Shopify ヘッドレスストアにBraze SDKを実装することで、セッション、匿名のユーザー行動、チェックアウト前のショッパーアクション、そして開発チームと一緒に選択したカスタムイベントやカスタム属性を含むオンサイトアクティビティをトラッキングできます。また、In-App MessagesやContent Cardsなど、SDKがサポートするチャネルを追加することもできます。
- BrazeのShopify統合をインストールする
ShopifyストアをBrazeに接続すると、Shopify Webhookを通じて顧客、チェックアウト、注文、商品データにアクセスできるようになります。
統合を開始する前に、Shopify ストアフロントのチェックアウトサブドメインが正しく設定されていることを確認してください。詳細については、Migrate from the online store to Hydrogen を参照してください。
この設定が正しく行われないと、BrazeはShopifyチェックアウトWebhookを処理できません。また、ローカルの開発環境で統合をテストすることもできません。ストアフロントとチェックアウトページ間の共有ドメインに依存しているためです。
これらの目標を達成するには、以下のステップに従ってください。
Braze Web SDKを初期化してロードする
ステップ1: Braze Webサイトアプリを作成する
Brazeで、設定 > アプリ設定に移動し、アプリの追加を選択します。アプリ名に「Shopify」と入力します。
ショップ名は「Shopify」にする必要があります。そうしないと、統合が適切に機能しない場合があります。
ステップ2: サブドメインおよび環境変数の追加
- Shopify サブドメインをオンラインストアから Hydrogen にトラフィックをリダイレクトするように設定します。
- ログイン用のコールバック URI を追加します。(ドメインが追加されると、URIは自動的に追加されます。)
- Shopify 環境変数を設定します。
- ステップ1で作成したWebサイトアプリの値を使用して、次の2つの環境変数を作成します。
BRAZE_API_KEYBRAZE_API_URL
ステップ3: オンサイトトラッキングを有効にする
まず、Braze Web SDKを初期化します。NPMパッケージをインストールすることをお勧めします。
1
2
3
npm install --save @braze/web-sdk@5.4.0
# or, using yarn:
# yarn add @braze/web-sdk
Braze Web SDKバージョンは5.4.0である必要があります。
次に、最上位キーとしてこの設定を vite.config.js ファイルに含めます。
1
2
3
optimizeDeps: {
exclude: ['@braze/web-sdk']
}
NPMパッケージをインストールした後、Layout コンポーネント内部の useEffect フック内でSDKを初期化する必要があります。Hydrogenのバージョンに応じて、このコンポーネントは root.jsx または layout.jsx のいずれかのファイルにあります。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Add these imports
import * as braze from "@braze/web-sdk";
import { useEffect } from 'react';
export function Layout({children}) {
const nonce = useNonce();
// @type {RootLoader}
const data = useRouteLoaderData('root');
// Add useEffect call to initialize Braze SDK
useEffect(() => {
if(!braze.isInitialized()) {
braze.initialize(data.brazeApiKey, {
baseUrl: data.brazeApiUrl,
});
braze.openSession()
}
}, [data])
return (...);
}
ステップ2で作成した環境変数を使用して、値 data.brazeApiKey と data.brazeApiUrl をコンポーネントローダーに含める必要があります。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
export async function loader(args) {
// Start fetching non-critical data without blocking time to first byte
const deferredData = loadDeferredData(args);
// Await the critical data required to render initial state of the page
const criticalData = await loadCriticalData(args);
const {storefront, env} = args.context;
return {
...deferredData,
...criticalData,
publicStoreDomain: env.PUBLIC_STORE_DOMAIN,
// Add the two properties below to the returned value
brazeApiKey: env.BRAZE_API_KEY,
brazeApiUrl: env.BRAZE_API_URL,
shop: getShopAnalytics({
storefront,
publicStorefrontId: env.PUBLIC_STOREFRONT_ID,
}),
consent: {
checkoutDomain: env.PUBLIC_CHECKOUT_DOMAIN,
storefrontAccessToken: env.PUBLIC_STOREFRONT_API_TOKEN,
withPrivacyBanner: false,
// Localize the privacy banner
country: args.context.storefront.i18n.country,
language: args.context.storefront.i18n.language,
},
};
}
コンテンツセキュリティポリシー(通常は entry.server.jsx Hydrogen ファイルにある)は、ローカル環境でも本番環境でも、Brazeスクリプトの機能に影響を与える可能性があります。OxygenまたはカスタムデプロイメントでShopifyに送信されるプレビュービルドでテストすることをお勧めします。問題が発生した場合は、CSPを設定してJavaScriptが機能するようにする必要があります。
ステップ4: Shopifyアカウントログインイベントの追加
買い物客がアカウントにサインインし、ユーザー情報をBrazeに同期したタイミングを追跡します。これには、changeUser メソッドを呼び出して、Braze external IDで顧客を識別することが含まれます。
現在のところ、カスタムBraze external IDをサポートするガイダンスはありません。統合にこれが必要な場合は、カスタマーサクセスマネージャーにお問い合わせください。
開始する前に、Hydrogen内で顧客ログインが動作するようにコールバックURIが設定されていることを確認してください。詳細については、Using the Customer Account API with Hydrogen を参照してください。
- コールバックURIを設定した後、Braze SDKを呼び出す関数を定義します。新しいファイル(
Tracking.jsxなど)を作成し、コンポーネントからインポートします。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import * as braze from "@braze/web-sdk";
export function trackCustomerLogin(customerData, storefrontUrl) {
const customerId = customerData.id.substring(customerData.id.lastIndexOf('/') + 1)
const customerSessionKey = `ab.shopify.shopify_customer_${customerId}`;
const alreadySetCustomerInfo = sessionStorage.getItem(customerSessionKey);
if(!alreadySetCustomerInfo) {
const user = braze.getUser()
// To use Shopify customer ID as Braze External ID, use:
// braze.changeUser(customerId)
// To use Shopify customer email as Braze External ID, use:
// braze.changeUser(customerData.emailAddress?.emailAddress)
// To use hashing for email addresses, apply hashing before calling changeUser
// To use your own custom ID as the Braze External ID, pass that value to the changeUser call.
user.setFirstName(customerData.firstName);
user.setLastName(customerData.lastName);
if(customerData.emailAddress.emailAddress) {
user.setEmail(customerData.emailAddress?.emailAddress);
}
if(customerData.phoneNumber?.phoneNumber) {
user.setPhoneNumber(customerData.phoneNumber?.phoneNumber);
}
braze.logCustomEvent(
"shopify_account_login",
{ source: storefrontUrl }
)
sessionStorage.setItem(customerSessionKey, customerId);
}
}
- Braze SDKを初期化するのと同じ
useEffectフックで、この関数の呼び出しを追加します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { trackCustomerLogin } from './Tracking';
export function Layout({children}) {
const nonce = useNonce();
// @type {RootLoader}
const data = useRouteLoaderData('root');
useEffect(() => {
if(!braze.isInitialized()) {
braze.initialize(data.brazeApiKey, {
baseUrl: data.brazeApiUrl,
enableLogging: true,
});
braze.openSession()
}
// Add call to trackCustomerLogin function
data.isLoggedIn.then((isLoggedIn) => {
if(isLoggedIn) {
trackCustomerLogin(data.customerData, data.publicStoreDomain)
}
})
}, [data])
- ファイル
app/graphql/customer-account/CustomerDetailsQuery.jsにあるCustomer API GraphQLクエリで、顧客のメールアドレスと電話番号を取得します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
export const CUSTOMER_FRAGMENT = `#graphql
fragment Customer on Customer {
id
firstName
lastName
emailAddress {
emailAddress
}
phoneNumber {
phoneNumber
}
defaultAddress {
...Address
}
addresses(first: 6) {
nodes {
...Address
}
}
}
fragment Address on CustomerAddress {
id
formatted
firstName
lastName
company
address1
address2
territoryCode
zoneCode
city
zip
phoneNumber
}
`;
- 最後に、ローダー関数で顧客データを読み込みます。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Add import for GraphQL Query
import { CUSTOMER_DETAILS_QUERY } from './graphql/customer-account/CustomerDetailsQuery';
export async function loader(args) {
// Start fetching non-critical data without blocking time to first byte
const deferredData = loadDeferredData(args);
// Await the critical data required to render initial state of the page
const criticalData = await loadCriticalData(args);
const {storefront, env} = args.context;
// Add GraphQL call to Customer API
const isLoggedIn = await deferredData.isLoggedIn;
let customerData;
if (isLoggedIn) {
const { data, errors } = await args.context.customerAccount.query(
CUSTOMER_DETAILS_QUERY,
);
customerData = data.customer
} else {
customerData = {}
}
return {
...deferredData,
...criticalData,
publicStoreDomain: env.PUBLIC_STORE_DOMAIN,
brazeApiKey: env.BRAZE_API_KEY,
brazeApiUrl: env.BRAZE_API_URL,
// Add the property below to the returned value
customerData: customerData,
shop: getShopAnalytics({
storefront,
publicStorefrontId: env.PUBLIC_STOREFRONT_ID,
}),
consent: {
checkoutDomain: env.PUBLIC_CHECKOUT_DOMAIN,
storefrontAccessToken: env.PUBLIC_STOREFRONT_API_TOKEN,
withPrivacyBanner: false,
// Localize the privacy banner
country: args.context.storefront.i18n.country,
language: args.context.storefront.i18n.language,
},
};
}
ステップ5: 製品の閲覧イベントとカートの更新イベントのトラッキングを追加する
製品の閲覧イベント
- この関数を
Tracking.jsxファイルに追加します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
export function trackProductViewed(product, storefrontUrl) {
const eventData = {
product_id: product.id.substring(product.id.lastIndexOf('/') + 1),
product_name: product.title,
variant_id: product.selectedOrFirstAvailableVariant.id.substring(product.selectedOrFirstAvailableVariant.id.lastIndexOf('/') + 1),
image_url: product.selectedOrFirstAvailableVariant.image?.url,
product_url: `${storefrontUrl}/products/${product.handle}`,
price: product.selectedOrFirstAvailableVariant.price.amount,
currency: product.selectedOrFirstAvailableVariant.price.currencyCode,
source: storefrontUrl,
type: ["price_drop", "back_in_stock"],
metadata: {
sku: product.selectedOrFirstAvailableVariant.sku
}
}
braze.logCustomEvent(
"ecommerce.product_viewed",
eventData
)
}
- ユーザーが製品ページにアクセスするたびにこの関数を呼び出すには、ファイル
app/routes/products.$handle.jsx内のProductコンポーネントにuseEffectフックを追加します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import { trackProductViewed } from '~/tracking';
import { useEffect } from 'react';
export default function Product() {
// @type {LoaderReturnData}
// retrieve storefrontUrl to be passed into trackProductViewed
const {product, storefrontUrl} = useLoaderData();
// Add useEffect hook for tracking product_viewed event
useEffect(() => {
trackProductViewed(product, storefrontUrl)
}, [])
return (...)
}
- 「storefrontUrl」の値を追加します(デフォルトではコンポーネントローダーに含まれていないため)。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
async function loadCriticalData({context, params, request}) {
const {handle} = params;
const {storefront} = context;
if (!handle) {
throw new Error('Expected product handle to be defined');
}
const [{product}] = await Promise.alll([
storefront.query(PRODUCT_QUERY, {
variables: {handle, selectedOptions: getSelectedProductOptions(request)},
}),
// Add other queries here, so that they are loaded in parallel
]);
if (!product?.id) {
throw new Response(null, {status: 404});
}
return {
product,
// Add this property to the returned value
storefrontUrl: context.env.PUBLIC_STORE_DOMAIN,
};
}
カート更新イベント
この連携では、BrazeがWebhookを正しいユーザープロファイルに一致させるために、ユーザーエイリアスは以下の形式を使用する必要があります。
alias_label:shopify_cart_${cartToken}alias_name:shopify_cart_token
cart_updatedイベントを追跡し、カートトークンを設定する関数を定義します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
export function trackCartUpdated(cart, storefrontUrl) {
const eventData = {
cart_id: cart.id,
total_value: cart.cost.totalAmount.amount,
currency: cart.cost.totalAmount.currencyCode,
products: cart.lines.nodes.map((line) => {
return {
product_id: line.merchandise.product.id.toString(),
product_name: line.merchandise.product.title,
variant_id: line.merchandise.id.toString(),
image_url: line.merchandise.image.url,
product_url: `${storefrontUrl}/products/${line.merchandise.product.handle}`,
quantity: Number(line.quantity),
price: Number(line.cost.totalAmount.amount / Number(line.quantity))
}
}),
source: storefrontUrl,
metadata: {},
};
braze.logCustomEvent(
"ecommerce.cart_updated",
eventData
)
}
export function setCartToken(cart) {
const cartId = cart.id.substring(cart.id.lastIndexOf('/') + 1)
const cartToken = cartId.substring(0, cartId.indexOf("?key="));
if (cartToken) {
const cartSessionKey = `ab.shopify.shopify_cart_${cartToken}`;
const alreadySetCartToken = sessionStorage.getItem(cartSessionKey);
if (!alreadySetCartToken) {
braze.getUser().addAlias("shopify_cart_token", `shopify_cart_${cartToken}`)
braze.requestImmediateDataFlush();
sessionStorage.setItem(cartSessionKey, cartToken);
}
}
}
- フェッチャーアクションから
cartオブジェクトを返し、Brazeがそのプロパティにアクセスできるようにします。app/routes/cart.jsxファイルに移動して、action関数に以下を追加します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
export async function action({request, context}) {
const {cart} = context;
...
switch (action) {
case CartForm.ACTIONS.LinesAdd:
result = await cart.addLines(inputs.lines);
break;
...
}
const cartId = result?.cart?.id;
const headers = cartId ? cart.setCartId(result.cart.id) : new Headers();
const {cart: cartResult, errors, warnings} = result;
const redirectTo = formData.get('redirectTo') ?? null;
if (typeof redirectTo === 'string') {
status = 303;
headers.set('Location', redirectTo);
}
return data(
{
cart: cartResult,
// Add these two properties to the returned value
updatedCart: await cart.get(),
storefrontUrl: context.env.PUBLIC_STORE_DOMAIN,
errors,
warnings,
analytics: {
cartId,
},
},
{status, headers},
);
}
Remixフェッチャーの詳細については、useFetcher を参照してください。
- Hydrogenストアは通常、カートオブジェクトの状態を管理する
CartFormコンポーネントを定義します。このコンポーネントは、カート内のアイテムの追加、削除、数量の変更時に使用されます。フォームフェッチャーの状態が変わるたびに(ユーザーカートが更新されるたびに)trackCartUpdated関数を呼び出すuseEffectフックをAddToCartButtonコンポーネントに追加します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Add imports
import { trackCartUpdated, setCartToken } from '~/tracking';
import { useEffect } from 'react';
import { useFetcher } from '@remix-run/react';
export function AddToCartButton({
analytics,
children,
disabled,
lines,
onClick,
}) {
// Define a new Fetcher to be used for tracking cart updates
const fetcher = useFetcher({ key: "cart-fetcher" });
// Add useEffect hook for tracking cart_updated event and setting cart token alias
useEffect(() => {
if(fetcher.state === "idle" && fetcher.data) {
trackCartUpdated(fetcher.data.updatedCart, fetcher.data.storefrontUrl)
setCartToken(fetcher.data.updatedCart);
}
}, [fetcher.state, fetcher.data])
// Add the fetcherKey prop to the CartForm component
return (
<CartForm route="/cart" inputs= fetcherKey="cart-fetcher" action={CartForm.ACTIONS.LinesAdd}>
{(fetcher) => (
<>
<input
name="analytics"
type="hidden"
value={JSON.stringify(analytics)}
/>
<button
type="submit"
onClick={onClick}
disabled={disabled ?? fetcher.state !== 'idle'}
>
{children}
</button>
</>
)}
</CartForm>
);
}
- カートから既存の製品を更新するアクションには、同じ
fetcherKeyを使用します。CartLineRemoveButtonとCartLineUpdateButtonコンポーネント(デフォルトではファイルapp/components/CartLineItem.jsxにある)に以下を追加します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function CartLineRemoveButton({lineIds, disabled}) {
// Add the fetcherKey prop to the CartForm component
return (
<CartForm
fetcherKey="cart-fetcher"
route="/cart"
action={CartForm.ACTIONS.LinesRemove}
inputs=
>
<button disabled={disabled} type="submit">
Remove
</button>
</CartForm>
);
}
function CartLineUpdateButton({children, lines}) {
// Add the fetcherKey prop to the CartForm component
return (
<CartForm
route="/cart"
fetcherKey="cart-fetcher"
action={CartForm.ACTIONS.LinesUpdate}
inputs=
>
{children}
</CartForm>
);
}
BrazeのShopify統合をインストールする
ステップ1: Shopifyストアを接続する
Shopifyパートナーページに移動して設定を開始します。まず、Begin Setup を選択し、Shopify App StoreからBrazeアプリケーションをインストールします。ガイドの手順に従って、インストールプロセスを完了します。

ステップ2: Braze SDKを有効にする
Shopify Hydrogenまたはヘッドレスストアの場合は、Custom setup オプションを選択します。
オンボーディングプロセスを続行する前に、Shopify WebサイトでBraze SDKが有効になっていることを確認してください。

ステップ3: Shopifyデータを追跡する
Shopify Webhookを利用するShopifyイベントと属性をさらに追加することで、統合を強化します。この統合で追跡されるデータの詳細については、Shopifyデータ機能を参照してください。

ステップ4: 履歴バックフィル(オプション)
カスタム設定を通じて、Shopify統合を接続する前の過去90日間のShopify顧客と注文を読み込むオプションがあります。この初期データ読み込みを含めるには、初期データ読み込みオプションのチェックボックスをオンにします。
後でバックフィルを実行する場合は、ここで初期セットアップを完了し、後からこのステップに戻ることができます。

この表には、バックフィルによって最初に読み込まれるデータが掲載されています。
| Braze推奨イベント | Shopifyカスタムイベント | Brazeの標準属性項目 | Brazeサブスクリプションステータス |
|---|---|---|---|
|
|
|
|
ステップ5: カスタムデータトラッキングの設定(上級)
Braze SDKを使用すると、この統合でサポートされているデータを超えるカスタムイベントやカスタム属性を追跡できます。カスタムイベントは、以下のようなストアでの固有のインタラクションをキャプチャします。
| カスタムイベント | カスタム属性 |
|---|---|
|
|
イベントやカスタム属性をログに記録するには、SDKがユーザーのデバイス上で初期化(アクティビティをリッスン)されている必要があります。カスタムデータのロギングについては、User object と logCustomEvent を参照してください。
ステップ6: ユーザーの管理方法の設定(オプション)
ドロップダウンから external_id タイプを選択します。

メールアドレスまたはハッシュ化されたメールアドレスをBraze external IDとして使用することで、データソース全体でのID管理を簡素化できます。ただし、ユーザーのプライバシーとデータセキュリティに対する潜在的なリスクを考慮することが重要です。
- 推測可能な情報: メールアドレスは推測されやすく、攻撃に対して脆弱です。
- 悪用のリスク: 悪意のあるユーザーがWebブラウザーを改ざんし、他人のメールアドレスをexternal IDとして送信した場合、機密メッセージやアカウント情報にアクセスされる可能性があります。
デフォルトでは、BrazeはShopifyから取得したメールを自動的に小文字に変換してからexternal IDとして使用します。メールまたはハッシュメールをexternal IDとして使用している場合は、external IDとして割り当てる前、または他のデータソースからハッシュする前に、メールアドレスも小文字に変換されていることを確認してください。これにより、external IDの不一致を防ぎ、Brazeでの重複ユーザープロファイルの作成を回避できます。
次のステップは、external IDの選択によって異なります。
- カスタムexternal IDタイプを選択した場合: ステップ6.1〜6.3を実行して、カスタムexternal IDの設定を行います。
- Shopify顧客ID、メール、またはハッシュメールを選択した場合: ステップ6.1〜6.3をスキップし、ステップ6.4に直接進みます。
ステップ6.1: braze.external_id メタフィールドを作成する
- Shopifyの管理パネルで、Settings > Metafields に移動します。
- Customers > Add definition を選択します。
- Namespace and key に
braze.external_idと入力します。 - Type で ID Type を選択します。
メタフィールドが作成されたら、顧客に対して値を入力します。次のアプローチをお勧めします。
- 顧客作成Webhookをリッスンする:
customer/createイベントをリッスンするWebhookを設定します。これにより、新しい顧客の作成時にメタフィールドを書き込むことができます。 - 既存の顧客をバックフィルする: Admin API または Customer API を使用して、以前に作成した顧客のメタフィールドをバックフィルします。
ステップ6.2: external IDを取得するエンドポイントを作成する
Brazeがexternal IDを取得するために呼び出せる公開エンドポイントを作成する必要があります。これにより、Shopifyが braze.external_id メタフィールドを直接提供できないシナリオでも、BrazeがIDを取得できます。
エンドポイント仕様
メソッド: GET
Brazeは、次のパラメーターをエンドポイントに送信します。
| パラメーター | 必須 | データタイプ | 説明 |
|---|---|---|---|
| shopify_customer_id | はい | 文字列 | Shopify顧客ID。 |
| shopify_storefront | はい | 文字列 | リクエストのストアフロント名。例: <storefront_name>.myshopify.com |
| email_address | いいえ | 文字列 | ログインユーザーのメールアドレス。 このフィールドは、特定のWebhookシナリオでは欠落している場合があります。エンドポイントロジックでは、ここでnull値を考慮する必要があります(たとえば、内部ロジックで必要な場合はshopify_customer_idを使用してメールを取得します)。 |
サンプルエンドポイント
1
GET https://mystore.com/custom_id?shopify_customer_id=1234&[email protected]&shopify_storefront=dev-store.myshopify.com
期待される応答
Brazeは、external IDのJSONを返す 200 ステータスコードを期待します。
1
2
3
{
"external_id": "my_external_id"
}
検証
shopify_customer_id と email_address(存在する場合)がShopifyの顧客値と一致することを検証することが重要です。Shopify Admin API または Customer API を使用してこれらのパラメーターを検証し、正しい braze.external_id メタフィールドを取得できます。
失敗時の動作とマージ
200 以外のステータスコードは失敗と見なされます。
- マージへの影響: エンドポイントが失敗した場合(
200以外を返す、またはタイムアウトした場合)、Brazeはexternal IDを取得できません。そのため、ShopifyユーザーとBrazeユーザープロファイル間のマージは、その時点では行われません。 - 再試行ロジック: Brazeは標準的な即時ネットワーク再試行を試みますが、失敗が続く場合、マージは次の該当イベントまで延期されます(たとえば、次回ユーザーがプロファイルを更新するか、チェックアウトを完了したとき)。
- サポート性: タイムリーなユーザーマージに対応するには、エンドポイントの高可用性を確保し、オプションの
email_addressフィールドを適切に処理するようにしてください。
ステップ6.3: external IDを入力する
ステップ6を繰り返し、Brazeのexternal IDタイプとしてカスタムexternal IDを選択した後、エンドポイントURLを入力します。
考慮事項
- Brazeがエンドポイントにリクエストを送信したときにexternal IDが生成されていない場合、
changeUser関数が呼び出されると、統合はデフォルトでShopify顧客IDを使用します。このステップは、匿名ユーザープロファイルと識別済みユーザープロファイルをマージするために重要です。そのため、一時的にワークスペース内にさまざまなタイプのexternal IDが存在する場合があります。 - external IDが
braze.external_idメタフィールドで使用可能な場合、統合はこのexternal IDを優先して割り当てます。- 以前にShopify顧客IDがBraze external IDとして設定されていた場合は、
braze.external_idメタフィールドの値に置き換えられます。
- 以前にShopify顧客IDがBraze external IDとして設定されていた場合は、
ステップ6.4: Shopifyからメールや SMSのオプトインを収集する(オプション)
Shopifyからメールまたは SMSマーケティングのオプトインを収集するオプションもあります。
メールやSMSチャネルを使用している場合、メールやSMSマーケティングのオプトイン状態をBrazeに同期できます。ShopifyからメールマーケティングオプトインをBrazeに同期すると、Brazeはその特定のストアに関連付けられたすべてのユーザーのメールサブスクリプショングループを自動的に作成します。このサブスクリプショングループに一意の名前を作成する必要があります。

Shopify概要で説明されているように、サードパーティ製のキャプチャフォームを使用する場合は、開発者がBraze SDKコードを統合する必要があります。これにより、フォーム送信からメールアドレスとグローバルメールサブスクリプションステータスをキャプチャできます。具体的には、theme.liquid ファイルに以下のメソッドを実装してテストする必要があります。
- setEmail: ユーザープロファイルにメールアドレスを設定します
- setEmailNotificationSubscriptionType: グローバルメールサブスクリプションステータスを更新します
ステップ7: 製品を同期する(オプション)
Shopifyストアの全商品をBrazeカタログに同期し、より詳細なメッセージングのパーソナライゼーションを実現できます。自動更新はほぼリアルタイムで行われるため、カタログには常に最新の商品詳細が反映されます。詳細については、Shopify製品同期を参照してください。

ステップ8: チャネルを有効にする
Shopify直接統合を使用してIn-App Messages、Content Cards、およびフィーチャーフラグを有効にするには、各チャネルをSDKに追加します。以下の各チャネルのドキュメントリンクに従ってください。
- In-App Messages: リード獲得フォームのユースケースでIn-App Messagesを有効にするには、In-App Messages を参照してください。
- Content Cards: 受信トレイやWebサイトバナーのユースケースでContent Cardsを有効にするには、Content Cards を参照してください。
- フィーチャーフラグ: サイト実験のユースケースでフィーチャーフラグを有効にするには、フィーチャーフラグを参照してください。
ステップ9: 設定を完了する
すべてのステップを終えたら、Finish Setup を選択してパートナーページに戻ります。次に、表示されるバナーの指示に従って、Shopify管理ページでBrazeアプリの埋め込みを有効にします。

サンプルコード
shopify-hydrogen-example は、前のステップで説明したすべてのコードを含むHydrogenアプリの例です。