Skip to content

Shopify カスタム統合設定

このページでは、カスタムストアフロントを使用して、Shopify Hydrogen ストアやヘッドレス Shopify ストアとBrazeを統合する方法を説明します。

このガイドでは、Shopifyの Hydrogen フレームワークを例にしています。ただし、ブランドが「ヘッドレス」フロントエンド設定でストアのバックエンドに Shopify を使用している場合も、同様のアプローチをとることができます。

Shopify のヘッドレスストアをBrazeと統合するには、以下の2つの目標を達成する必要があります。

  1. Braze Web SDKを初期化してロードし、オンサイトトラッキングを有効にする

    手動で Shopify Webサイトにコードを追加して、Brazeオンサイトトラッキングを有効にします。Shopify ヘッドレスストアにBraze SDKを実装することで、セッション、匿名のユーザー行動、チェックアウト前のショッパーアクション、そして開発チームと一緒に選択したカスタムイベントカスタム属性を含むオンサイトアクティビティをトラッキングできます。また、アプリ内メッセージやContent Cardsなど、SDKがサポートするチャネルを追加することもできます。
  1. BrazeのShopify統合をインストールする

    ShopifyストアをBrazeに接続すると、Shopify webhookを通じて顧客、チェックアウト、注文、商品データにアクセスできるようになります。

これらの目標を達成するには、以下のステップに従ってください。

Braze Web SDKの初期化と読み込み

ステップ1:Webサイトアプリを選択してSDK認証情報をコピーする

Hydrogen ストアフロントにコードを追加する前に、Shopifyストアを接続してカスタムセットアップのオンボーディングを開始してください。ストアをまだ接続していない場合は、Shopifyストアを接続するを完了してから、Braze SDKを有効にするに進み、カスタムセットアップを選択します。

カスタムセットアップフローでは、ヘッドレスストアフロント用のWebサイトアプリを選択するよう求められます。

  1. 既存のWebサイトアプリを選択するか、新しいアプリを作成します。アプリには Shopify 以外の任意の名前を付けることができます。Shopify はBrazeが標準のShopify統合パスのために予約しています。
  2. Brazeは選択したアプリのAPIキーとベースURL(SDKエンドポイント)をオンボーディングステップに表示します。それぞれの値のコピーを選択してください。設定 > アプリ設定を開く必要はありません。
  3. コピーしたAPIキーを BRAZE_API_KEY として、SDKエンドポイントを BRAZE_API_URL としてShopifyの環境変数で使用します(ステップ2)。

ストアを接続した後、設定 > アプリ設定で選択したWebサイトアプリの名前を変更できます。Shopify統合に接続されている間はアプリを削除できません。

ステップ2:サブドメインと環境変数を追加する

  1. Shopifyサブドメインを設定して、オンラインストアからHydrogenにトラフィックをリダイレクトします。
  2. ログイン用のコールバックURIを追加します(ドメインが追加されると、URIは自動的に追加されます)。
  3. Shopify環境変数を設定します:
    • ステップ1のカスタムセットアップオンボーディング時にコピーしたAPIキーとSDKエンドポイントを使用して、2つの環境変数を作成します。
    • BRAZE_API_KEY
    • BRAZE_API_URL

ステップ3:オンサイトトラッキングを有効にする

最初のステップは、Braze Web SDKを初期化することです。NPMパッケージをインストールすることをお勧めします:

1
2
3
npm install --save @braze/web-sdk@6.8.0
# or, using yarn:
# yarn add @braze/web-sdk

次に、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 (...);
}

data.brazeApiKeydata.brazeApiUrl の値は、ステップ2で作成した環境変数を使用してコンポーネントローダーに含める必要があります:

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,
    },
  };
}

ステップ4:Shopifyアカウントログインイベントを追加する

買い物客がアカウントにサインインし、ユーザー情報をBrazeに同期するタイミングを追跡します。これには、Braze external IDで顧客を識別するための changeUser メソッドの呼び出しが含まれます。

開始する前に、Hydrogen内で顧客ログインが機能するようにコールバックURIを設定していることを確認してください。詳細については、HydrogenでのCustomer Account APIの使用を参照してください。

  1. コールバック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);
  }
}
  1. 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])
  1. Customer API GraphQLクエリで顧客のメールアドレスと電話番号をフェッチします。このクエリは app/graphql/customer-account/CustomerDetailsQuery.js ファイルにあります:
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. 最後に、ローダー関数で顧客データを読み込みます:
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:Product ViewedイベントとCart Updatedイベントのトラッキングを追加する

Product Viewedイベント

  1. 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
  )
}
  1. ユーザーが商品ページにアクセスするたびにこの関数を呼び出すには、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 (...)
}
  1. 「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,
  };
}

Cart Updatedイベント

  1. 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);
    }
  }
}
  1. Brazeがそのプロパティにアクセスできるよう、フェッチャーアクションから cart オブジェクトを返します。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を参照してください。

  1. Hydrogenストアでは通常、カートオブジェクトの状態を管理する CartForm コンポーネントを定義しており、カート内のアイテムの追加、削除、数量変更時に使用されます。AddToCartButton コンポーネントに別の useEffect フックを追加して、フォームフェッチャーの状態が変更されるたびに(ユーザーのカートが更新されるたびに)trackCartUpdated 関数を呼び出すようにします:
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>
  );
}
  1. カートの既存商品を更新するアクションにも同じ fetcherKey を使用します。CartLineRemoveButtonCartLineUpdateButton コンポーネント(デフォルトでは 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アプリケーションをインストールします。ガイドに従ってインストールプロセスを完了してください。

BrazeダッシュボードのShopifyインテグレーション設定ページ。

ステップ2:Braze SDKを有効にする

Shopify Hydrogenまたはヘッドレスストアの場合は、Custom setup オプションを選択します。

カスタム設定にはWebサイトアプリピッカーが含まれています。ストアフロントを動かすアプリを選択または作成し、オンボーディングステップに表示されるAPIキーとSDKエンドポイントをコピーします。詳細については、ステップ1:Webサイトアプリを選択してSDK認証情報をコピーするを参照してください。

オンボーディングプロセスを続行する前に、これらの認証情報を使用してBraze SDKをShopify Webサイトに追加したことを確認してください。

Braze SDKを有効にする設定ステップ。

ステップ3:Shopifyデータをトラッキングする

Shopifyイベントと属性を追加してインテグレーションを強化します。これらはShopify webhookによって動作します。このインテグレーションでトラッキングされるデータの詳細については、Shopifyデータ機能を参照してください。

Shopifyデータをトラッキングする設定ステップ。

ステップ4:過去データのバックフィル(オプション)

カスタム設定では、標準インテグレーションと同じ過去のShopifyデータロードをオプションで含めることができます。これには、インテグレーション完了日から遡って過去90日間の注文イベントと過去1年間のユーザープロファイルが含まれます。この初期データロードを含めるには、初期データロードオプションのチェックボックスを選択してください。

後でバックフィルを実行したい場合は、今は初期設定を完了し、後からこのステップに戻ることができます。

過去データのバックフィル設定セクション。

初期ロードのデータ一覧、収益レポートの動作、同期の監視については、過去データのバックフィルを参照してください。

ステップ5:カスタムデータトラッキング設定(上級)

Braze SDKを使用すると、このインテグレーションでサポートされているデータを超えるカスタムイベントやカスタム属性をトラッキングできます。カスタムイベントは、ストアでのユニークなインタラクションをキャプチャします。例:

ステップ5:カスタムデータトラッキング設定(上級)
カスタムイベント カスタム属性
  • カスタム割引コードの使用
  • パーソナライズされた商品レコメンデーションとのインタラクション
  • お気に入りのブランドや商品
  • 希望するショッピングカテゴリ
  • メンバーシップまたはロイヤルティステータス

SDKは、イベントやカスタム属性をログに記録するために、ユーザーのデバイス上で初期化(アクティビティのリスニング)されている必要があります。カスタムデータのログ記録について詳しくは、User objectおよびlogCustomEventを参照してください。

ステップ6:ユーザー管理方法を設定する(オプション)

ドロップダウンからexternal_idタイプを選択します。

「購読者を収集」セクション。

デフォルトでは、BrazeはShopifyからのメールをexternal IDとして使用する前に自動的に小文字に変換します。メールアドレスまたはハッシュ化されたメールアドレスをexternal IDとして使用している場合は、他のデータソースからexternal IDとして割り当てる前またはハッシュ化する前に、メールアドレスも小文字に変換されていることを確認してください。これにより、external IDの不一致を防ぎ、Brazeで重複したユーザープロファイルが作成されることを回避できます。

ステップ6.1:braze.external_idメタフィールドを作成する

  1. Shopify管理パネルで、設定 > メタフィールドに移動します。
  2. 顧客 > 定義を追加を選択します。
  3. 名前空間とキーbraze.external_idと入力します。
  4. タイプIDタイプを選択します。

メタフィールドが作成されたら、顧客に対してデータを入力します。以下のアプローチを推奨します:

  • 顧客作成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 はい String Shopify顧客ID。
shopify_storefront はい String リクエストのストアフロント名。例:<storefront_name>.myshopify.com
email_address いいえ String ログインユーザーのメールアドレス。

特定の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_idemail_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が一時的に共存する期間が発生する場合があります。
  • braze.external_idメタフィールドでexternal IDが利用可能になると、インテグレーションはこのexternal IDを優先的に割り当てます。
    • Shopifyの顧客IDが以前Brazeのexternal IDとして設定されていた場合、braze.external_idメタフィールドの値に置き換えられます。

ステップ6.4:ShopifyからメールまたはSMSオプトインを収集する(オプション)

ShopifyからメールまたはSMSマーケティングオプトインを収集するオプションがあります。

メールまたはSMSチャネルを使用している場合は、メールおよびSMSマーケティングオプトインのステータスをBrazeに同期できます。Shopifyからメールマーケティングオプトインを同期すると、Brazeはその特定のストアに関連付けられたすべてのユーザーに対してメール購読グループを自動的に作成します。この購読グループには一意の名前を作成する必要があります。

メールまたはSMSマーケティングオプトインを収集するオプション付きの「購読者を収集」セクション。

ステップ7:商品を同期する(オプション)

Shopifyストアのすべての商品をBrazeカタログに同期して、より深いメッセージングパーソナライゼーションを実現できます。自動更新はほぼリアルタイムで行われるため、カタログには常に最新の商品詳細が反映されます。詳しくは、Shopify商品同期をご覧ください。

商品データをBrazeに同期する設定ステップ。

ステップ8:チャネルを有効化する

Shopifyダイレクトインテグレーションを使用してアプリ内メッセージ、Content Cards、およびフィーチャーフラグを有効化するには、各チャネルをSDKに追加します。各チャネルについて提供されているドキュメントリンクに従ってください:

  • アプリ内メッセージ:リードキャプチャフォームのユースケース向けにアプリ内メッセージを有効化するには、アプリ内メッセージを参照してください。
  • Content Cards:受信トレイやWebサイトバナーのユースケース向けにContent Cardsを有効化するには、Content Cardsを参照してください。
  • フィーチャーフラグ:サイト実験のユースケース向けにフィーチャーフラグを有効化するには、フィーチャーフラグを参照してください。

ステップ9:設定を完了する

すべてのステップが完了したら、Finish Setup を選択してパートナーページに戻ります。次に、表示されるバナーの指示に従って、Shopify管理ページでBrazeアプリ埋め込みを有効化します。

インテグレーションの設定を完了するためにShopifyでBrazeアプリ埋め込みを有効化するよう促すバナー。

サンプルコード

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

New Stuff!