### Product Finder - Progressive Journey Example Source: https://dy.dev/docs/muse Example query for a product finder using a progressive journey, collecting specific user preferences step-by-step. ```json { "query": { "text": "Suggest products based on these preferences: Skin type: Dry, Age: 44, Concern: Fine lines, Product type: Moisturizer, Texture preference: Lightweight cream, Additional preference: Fragrance-free." } } ``` -------------------------------- ### Post Page Context Example (Media) Source: https://dy.dev/docs/code-context Example script to set the recommendation context for a post page, typically used in media sites. ```javascript ``` -------------------------------- ### Product Page Context Example (E-commerce/Financial) Source: https://dy.dev/docs/code-context Example script to set the recommendation context for a product page, typically used in e-commerce or financial sites. ```javascript ``` -------------------------------- ### Product Search - Conversational Intent Example Source: https://dy.dev/docs/muse Example query for enhancing search with conversational, intent-driven product discovery, including price and feature constraints. ```json { "query": { "text": "I'm looking for eco-friendly travel backpacks for hiking, preferably under $150." } } ``` -------------------------------- ### Application Started Event Source: https://dy.dev/reference/trackevents Reports that a user started the application process for a product. This event is REQUIRED FOR FINANCIAL INSTITUTIONS SECTIONS. ```APIDOC ## Application Started Event ### Description Reports that a user started the application process for a product. This event is REQUIRED FOR FINANCIAL INSTITUTIONS SECTIONS. ### Method POST ### Endpoint /track ### Request Body - **name** (EventName) - Required - The name of the event. - **properties** (object) - Required - The properties of the event. - **dyType** (string) - Required - Must be `add-to-cart-v1`. - **value** (Value) - Required - The monetary value associated with the event. - **currency** (Currency) - Optional - The currency of the value. - **productId** (CartProductIdEcom) - Required - The product ID. - **quantity** (Quantity) - Required - The total number of items added to the cart. - **cart** (CartEcom) - Optional - The cart's current state, including the last item added. Products are ordered from the first added to the cart to the most recent. Pass the updated cart with the newly added products to ensure that the cart state is fully in sync with your system. ### Request Example ```json { "name": "Application Started", "properties": { "dyType": "add-to-cart-v1", "value": 400, "currency": "EUR", "productId": "item-34454", "quantity": 2, "cart": [ { "productId": "sku-4324-bg", "quantity": 2, "itemPrice": 100 }, { "productId": "item-34454", "quantity": 2, "itemPrice": 200 } ] } } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Suggest Request Example Source: https://dy.dev/reference/suggest An example of a request payload for the suggestion endpoint. It includes user, session, query, and context information. ```json { "user": { "active_consent_accepted": false, "dyid": "4350463893986789401", "dyid_server": "4350463893986789401" }, "session": { "dy": "ohyr6v42l9zd4bpinnvp7urjjx9lrssw" }, "query": { "text": "dre", "suggestions": [ { "type": "querySuggestions", "maxResults": 8 } ] }, "context": { "page": { "locale": "en_us" } } } ``` -------------------------------- ### SKU Location Example Source: https://dy.dev/docs/auto-detect-context This example shows how to specify the SKU location on a product page, referencing the dataLayer for the SKU value. This is crucial for context rule creation. ```javascript dataLayer[0].sku ``` -------------------------------- ### Install Dynamic Yield Addon Source: https://dy.dev/docs/sap-hybris Install the Dynamic Yield addon using the ant addoninstall command. Specify the addon name and the storefront template name. ```bash ant addoninstall -Daddonnames="dynamicyieldaddon" -DaddonStorefront.="Storefront1" ``` -------------------------------- ### Choose Restaurant Recommendations Variation Example Source: https://dy.dev/docs/choose-variations-using-react-sdk This example demonstrates how to choose variations for a 'qsr-recs-campaign' using the `choose.chooseVariations` method. It handles success, warning, and error states, and extracts custom data and slots from the chosen variation. ```javascript React Native async function chooseRestaurantsRecsVariationExample() { await choose.chooseVariations({ page: Page.homePage({ location: 'ScreenName' }), selectorNames: ['qsr-recs-campaign'] }) .then((result) => { switch (result.status) { case 'SUCCESS': case 'WARNING': { // Find the choice with the name 'qsr-recs-campaign' const choice = result.choices?.find( (choice) => choice.name === 'qsr-recs-campaign' ); if (isQsrProductRecsChoice(choice)) { // Assuming there is only one variation const custom = choice?.variations?.[0]?.payload?.data?.custom; const slots = choice?.variations?.[0]?.payload?.data?.slots; } else { // Log error about the expected campaign type } break; } case 'ERROR': // handle error break; } }) .catch((error) => { // handle error that happened during the request, like wrong parameter }); } ``` -------------------------------- ### Install React Native SDK Package Source: https://dy.dev/docs/react-sdk Install the specific version of the React Native SDK using npm. ```go React Native npm install @dynamicyield/react-native-sdk@1.2.0 ``` -------------------------------- ### Example Usage and Results Source: https://dy.dev/docs/get-user-location Demonstrates the output of DY.geoCity and DY.geoFields. ```javascript > DY.geoCity > "US_NJ_Clifton" > DY.geoFields > {city="Clifton", state:"New Jersey", country:"United States"} ``` -------------------------------- ### Upgrade Magento Setup Source: https://dy.dev/docs/magento-2x Ensure that all modules, including the newly enabled Dynamic Yield integration, are properly registered and updated in the Magento setup. ```bash php magento setup:upgrade --keep-generated ``` -------------------------------- ### Choose Request Payload Example Source: https://dy.dev/reference/choose-variations This example demonstrates a typical request payload for choosing product variations. It includes user, session, selector, context, and options for an e-commerce page. ```json { "user": { "dyid": "-4350463893986789401", "dyid_server": "-4350463893986789401" }, "session": { "dy": "ohyr6v42l9zd4bpinnvp7urjjx9lrssw" }, "selector": { "names": [ "PDP Top Banner", "PDP Recs" ] }, "context": { "page": { "type": "PRODUCT", "data": [ "7383723-010" ], "location": "", "referrer": "", "locale": "en_US" }, "device": { "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", "ip": "54.100.200.255" }, "pageAttributes": { "customPageAttribute": "someValue" } }, "options": { "isImplicitPageview": false } } ``` -------------------------------- ### Product Feed Update Example Source: https://dy.dev/reference/updateproductfeed This example demonstrates how to update product feed data, including adding a new product and deleting an existing one. It uses the 'UPDATE' and 'DELETE' actions respectively. Ensure the 'id' matches the product SKU. ```json { "requests": [ { "id": "56EF030B", "action": "UPDATE", "body": { "data": { "sku": "56EF030B", "group_id": "abc", "url": "http://www.example.com/abc-123", "name": "white sneakers", "price": 40.9, "in_stock": true, "image_url": "http://www.example.com/abc-123.png", "categories": "shoes|sneakers", "description": "The white sneakers that everybody wants", "publish_time": "2018-02-12T17:05:12", "keywords": "tag1|tag2" } } }, { "id": "56EF0889", "action": "DELETE" } ] } ``` -------------------------------- ### Chat with Assistant Example Source: https://dy.dev/docs/shopping-muse-using-react-native-sdk This example demonstrates how to initiate a chat with the Shopping Muse assistant using the React Native SDK. It shows how to structure the request with page and text parameters, and how to handle the response, including success, warning, and error states. The code also illustrates how to extract product data and widget information from the assistant's response. ```javascript async function chatWithAssistantExample() { await assistant.chatWithAssistant({ page: Page.categoryPage({ location: 'category-page', categories: ['kids', 'shhoes'] }), text: 'I want to buy something nice' }) .then((result) => { switch (result.status) { case 'SUCCESS': case 'WARNING': { const variation = result.choices?.[0]?.variations?.[0]; const data = variation?.payload?.data; if (data) { if (data.assistant) { // present helper to the customer } if (data.chatId) { // add chatId to the following request } data.widgets?.forEach((widget) => { const title = widget.title; console.log('Widget title:', title); const slots = widget.slots; if (slots) { for (const slot of slots) { const productData = slot.productData as DefaultRecsProductData | undefined; console.log(productData?.group_id ?? ''); console.log(productData?.name ?? ''); console.log(productData?.url ?? ''); console.log(productData?.price ?? ''); console.log(productData?.in_stock ?? ''); console.log(productData?.image_url ?? ''); console.log(productData?.categories ?? ''); console.log(productData?.keywords ?? ''); } } }); } break; } case 'ERROR': // handle error break; } }) .catch((error) => { // handle error that happened during the request, like wrong parameter }); } ``` -------------------------------- ### Successful Choice Response Example Source: https://dy.dev/reference/choose-variations This example shows a successful response after choosing a product variation. It details the selected choices, including their IDs, names, types, and decision IDs. ```json { "choices": [ { "id": 5, "name": "PDP Top Banner", "type": "DECISION", "decisionId": "aGVsbG8K", "variations": [ { "id": 12345, "name": "Control", "type": "CONTROL" } ] } ] } ``` -------------------------------- ### Track Application Start via JavaScript Source: https://dy.dev/docs/application Use this snippet to send an 'Application Started' event from the client-side using the DY.API. Ensure the properties accurately reflect the application event, including product and cart details. ```javascript DY.API("event", { name: "Application Started", properties: { dyType: "add-to-cart-v1", value: 400.00, currency: "EUR", productId: "item-34454", quantity: 2, cart: [ { productId: "sku-4324-bg", quantity: 2, itemPrice: 100, }, { productId: "item-34454", quantity: 2, itemPrice: 200 } ] } }); ``` -------------------------------- ### Search Request Example Source: https://dy.dev/reference/search An example of a complete search request payload, including query parameters, user information, session details, context, selector, and options. This can be used to understand the structure for making search API calls. ```json { "query": { "imageBase64": "bGlnaHQgd29yay4=", "text": "dress", "filters": [ { "field": "category", "values": [ "dresses", "tops" ] }, { "field": "price", "min": 100, "max": 200 } ], "pagination": { "numItems": 10, "offset": 0 }, "enableSpellCheck": true }, "user": { "active_consent_accepted": true, "dyid": "122113", "dyid_server": "3213213" }, "session": { "dy": "3123123" }, "context": { "page": { "type": "HOMEPAGE", "location": "https://shop.biz/nice-shirt-p76311.html", "referrer": "https://google.cz", "locale": "en_US" } }, "selector": { "name": "Visual Search" }, "options": { "returnAnalyticsMetadata": false, "isImplicitClientData": false } } ``` -------------------------------- ### Unauthorized Error Response Example Source: https://dy.dev/reference/suggest Example of an error response when the request is unauthorized. It includes an error code. ```json { "error": "401" } ``` -------------------------------- ### Product Feed Update Example Source: https://dy.dev/reference/updateproductfeed An example of a successful product feed update response, including a transaction ID. ```json { "ProductFeedUpdateExample01": { "value": { "success": true, "data": { "transaction_id": "MDcyNWM0MTEtYWZlZS00MjdkLWExYmYtMDlhMWIwNGFjMzg4LWZpZC0yMTYxNi10cy0xNTg2NjgxOTE0MDYwLXQtcGFydGlhbA==" } } } } ``` -------------------------------- ### Configuration Data Example Source: https://dy.dev/changelog/2026-01-tech-update This snippet shows configuration data, possibly for a system or application. It includes various parameters and settings. ```json { "page_title": "2026 Q1: Quarterly Technical Update", "page_description": "This document details the technical updates for the first quarter of 2026.", "page_summary": "The update covers various technical advancements and changes implemented during Q1 2026. It includes code snippets demonstrating specific functionalities and configurations.", "codeSnippets": [ { "title": "Data Encoding Example", "description": "This snippet demonstrates a method for encoding data, likely for transmission or storage. It appears to be a custom or proprietary encoding scheme.", "language": "binary", "codeList": [ { "language": "binary", "code": "gK8AAUAAAWBBJYAAAGBBYEElgAAAkIAiAISAAACCwgEAgEBAQECoAAAbwAApHkAAAAAAAAAAEZTSSABQAAAISIIsv4oAAAIsgHYAAAAAQAAAAADyQV4AAAAIAAAeJxczLnRAQEYgOFnj//en7VuPRg10IT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vvOBNfvM6VPFqa8A/3v+OPfA+Oa6wWfnZcZV/K786rnE40yyxVXnneJn9ygfHK/Qqz45XOay2Ha/xpvqf43X8Go43XvAmNzV/t9HcE/kgSpMylj0RjcSZVuY21rm4UEYWKjSJVmEqzrOofRUWjx0ZXRe6fqzTnug0muJGPgzSsHDbnOTWnOzWuI17WZSJVuLIP2jsvxJ3Gs26045PRFKKUJgi7MlsHOr+vLbnHLVDpWQpnrQSp1rGhVQ74iQuktLoPBaXWkaySBO1Y+3HS9yNcilOZR4WJpPKxMbkrSAYDod+XyszXn5XZ994HMhBGgZp0pWqlH5sspRdGjTZQ5AzICIloSRG0kMQMUJwhkZhuCVGkyO4sLGkQBFiSKwiJEVwTkZEmytCCh7pIIm4pkBT5xhNar07trLgBskDA1Kr/zparHJrwdqt2TTubYXSuQuO8Dmgwf53nC" } ] } ] } ``` -------------------------------- ### Initialize DYSdk with Parameters Source: https://dy.dev/docs/initializing-the-swift-sdk Call the `initialize` method once at the beginning of your SDK setup. This sets up the initial global configuration for the SDK. ```swift DYSdk.initialize(apiKey: "myApiKey", dataCenter: .eu, deviceType: .smartphone, sharedDevice: true, deviceId: "myId", channel: .app, ip: "123.45.67.890", locale: "en", isImplicitPageview: true, isImplicitImpressionMode: true) ``` -------------------------------- ### Invalid Unprocessable Request Example Source: https://dy.dev/reference/suggest Example of an error response for an unprocessable request. It contains a message indicating the issue. ```json { "message": "Unprocessable request." } ``` -------------------------------- ### Initialize React Native SDK Source: https://dy.dev/docs/initializing-the-react-sdk Use this snippet to set up the initial global configuration for the SDK. Ensure you provide your API key and select the correct data center. This method should be called once at the beginning of your SDK setup. ```javascript import { Channel, DataCenter, initialize, LogLevel, setLogLevel } from '@DynamicYield/react-native-sdk' async function initializeExample() { initialize({ apiKey: 'your-api-key', dataCenter: DataCenter.US, deviceId: 'example-deviceId', channel: Channel.APP, ip: '1.2.3.4', locale: 'en', isImplicitPageview: true, isImplicitImpressionMode: false, }).then(result => { // handle success console.log('Initialized:', result); }).catch(error => { // handle error console.error('Initialization failed:', error); }); } ``` -------------------------------- ### CSV Product Feed Example Source: https://dy.dev/docs/product-feed-file-examples This is an example of a CSV product feed file. It includes various product attributes and localized information. ```Text CSV "sku","group_id","categories","name","url","price","image_url","in_stock","keywords","display_price","gender","product","surface","best_for_1","best_for_2","color_1","color_2","cushioning","support","lng:en_US:name","lng:en_US:in_stock","lng:en_US:url","lng:en_US:image_url","lng:en_US:display_price","lng:en_GB:name","lng:en_GB:in_stock","lng:en_GB:url","lng:en_GB:image_url","lng:en_GB:display_price","lng:fr_FR:name","lng:fr_FR:in_stock","lng:fr_FR:url","lng:fr_FR:image_url","lng:fr_FR:display_price","lng:de_DE:name","lng:de_DE:in_stock","lng:de_DE:url","lng:de_DE:image_url","lng:de_DE:display_price" "1125-blue-42","1125","shoes|mens|road","Desert Eagle","https://www.shop.com/en_US/products/desert-eagle",225,"//images/en_US/shoe.png",true,"active|training|black|grey|direct|neutral","225$","mens","shoes","road","active","training","black","grey","direct","neutral","Desert Eagle",true,"https://www.shop.com/en_US/products/desert-eagle","//images/en_US/shoe.png","200$","Desert Eagle",false,"https://www.shop.com/en_GB/products/desert-eagle","//images/en_GB/shoe.png","200£","Aigle du désert",true,"https://www.shop.com/fr_FR/products/desert-eagle","//images/fr_FR/shoe.png","200€","Wüstenadler",true,"https://www.shop.com/de_DE/products/desert-eagle","//images/de_DE/shoe.png","200€" ``` -------------------------------- ### Generative Product Grids - Tailored Suggestions Source: https://dy.dev/docs/muse Example query for generating personalized product grids by suggesting a total look based on a specific item and category. ```json { "query": { "text": "Suggest total look for 'Blue Midi Dress', from the 'dresses' category" } } ``` -------------------------------- ### Successful Response Example (200) Source: https://dy.dev/reference This is an example of a successful response body when variations are chosen successfully. It details the structure of the 'choices' array and 'variations' object. ```JSON { "choices": [ { "id": "string", "name": "string", "type": "string", "variations": [ { "id": 0, "name": "string", "payload": {}, "rolloutFlag": true, "analyticsMetadata": {}, "groups": [ "string" ], "decisionId": "string", "allocationGroup": "string" } ], "cookies": [ { "name": "string", "value": "string", "maxAge": "string" } ], "warnings": [ { "code": "string", "message": "string" } ] } ] } ``` -------------------------------- ### API-only example (Node.JS) Source: https://dy.dev/reference/choosing-variations-api-only This Node.js snippet demonstrates how to make a POST request to the /v2/serve/user/choose endpoint. It includes setting up request options with headers, body, and handling the response. Ensure you replace 'your-api-key' with your actual API key. ```javascript var request = require("request"); var options = { method: 'POST', url: 'https://dy-api.com/v2/serve/user/choose', headers: {'content-type': 'application/json', 'dy-api-key': 'your-api-key'}, body: `{ "selector": { "names": [ "test1" ] }, "user": { "id": "customUserId123" }, "session": { "custom": "myCustomSession345" }, "context": { "page": { "type": "HOMEPAGE", "location": "https://example.org", "locale": "en_US", "data":[] }, "device": { "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", "ip": "54.100.200.255" } }, "options": { "isImplicitPageview": false, " returnAnalyticsMetadata": false }}` }; request(options, function (error, response, body) { if (error) throw new Error(error); console.log(body); }); ``` -------------------------------- ### Signup Event via Experience API (Server-Side) Source: https://dy.dev/docs/signup Server-side implementation of a signup event using the Experience API. This example shows basic event tracking with a client ID. ```json "events":[ { "name": "Signup", "properties": { "dyType": "signup-v1", "cuidType": "clientId", "cuid": "62eccc43b550b012b7ea7fb07e64baafb1508d8b715a55148ccf0f3322eab1a1" } } ] ``` -------------------------------- ### Initialize Kotlin SDK Source: https://dy.dev/docs/initialize-kotlin-sdk Call the `initialize` method once at the beginning of your SDK setup to configure global settings. Ensure you provide the required apiKey, dataCenter, and context. ```kotlin DYSdk.getInstance() .initialize( apiKey = "your-api-key", dataCenter = DataCenter.US, context = applicationContext, deviceId = "example-deviceId", channel = Channel.APP, ip = "1.2.3.4", locale = "en", isImplicitPageview = true, isImplicitImpressionMode = false, ) ``` -------------------------------- ### Product Feed Payload Example Source: https://dy.dev/reference/updateproductfeed This example demonstrates a request body for the Product Feed API, including operations for updating, deleting, and partially updating products. ```json { "requests": [ { "id": "abc-123", "action": "UPDATE", "body": { "data": { "sku": "abc-123", "group_id": "abc", "url": "http://www.example.com/abc-123", "name": "white sneakers", "price": 29.99, "in_stock": true, "image_url": "http://www.example.com/abc-123.png", "categories": "shoes|sneakers", "description": "The white sneakers that everybody wants", "publish_time": "2018-02-12T17:05:12", "keywords": "tag1|tag2", "any_other_field": "any other value" } } }, { "id": "abcd-123", "action": "delete" }, { "id": "abcde-123", "action": "partial", "body": { "data": { "price": 39.99 } } } ] } ``` -------------------------------- ### Transaction Status Example Source: https://dy.dev/reference/tracktransactionstatuswholetransaction An example response showing the status of items within a transaction. It includes item ID, status, timestamp, and an optional message for failures. ```json [ { "item": "abc-123", "status": "success", "time": "2023-03-30T08:20:35.827+0000" }, { "item": "abcde-123", "status": "failed", "time": "2023-03-30T08:20:23.324+0000", "message": "failed" }, { "item": "abcd-123", "status": "success", "time": "2023-03-30T08:20:30.005+0000", "message": "Item missing" } ] ``` -------------------------------- ### Choose Recommendations Variation Source: https://dy.dev/docs/choose-variations-using-swift-sdk This example demonstrates how to retrieve a variation for an API Recommendations campaign using the SDK. It shows how to access recommendation slots and custom data from the payload. ```swift func chooseRecsVariationExample() async throws { let chooseResult = await DYSdk.shared().choose.chooseVariations( selectorNames: ["recs-campaign"], page: Page.homePage(pageLocation: "ScreenName") ) switch chooseResult.status { case .success, .warning: if let choices = chooseResult.choices, let recsChoice = choices.first(where: { $0.name == "recs-campaign" }) { if recsChoice.type == .recsDecision { // Assuming there is only one variation if let firstVariation = recsChoice.variations.first, let payload = firstVariation.payload as? RecsPayload { let slots = payload.data.slots let custom = payload.data.custom // Use slots and custom data here } } } case .error: break // Handle error case } } ``` -------------------------------- ### Shopping Muse Payload Example Source: https://dy.dev/reference/shoppingmuse This is an example of a payload that can be sent to the Shopping Muse API. It includes the user's text prompt and an optional chatId for conversational context. ```json { "text": "Show me running shoes under $100", "chatId": "chat-7c31fe56" } ``` -------------------------------- ### Page-Level Rendering with JSON Source: https://dy.dev/page/almost-all-the-ways-to-use-experience-api This example shows how to fetch multiple campaign selectors at the page level for efficient data distribution to components. It's a common pattern for native mobile applications. ```javascript // Page-level code for a category page const response = await choose({ selector: { names: [ "category-hero", "category-recs", "promo-bar" ] }, // ... }); // Pass results down to components renderPage({ hero: findChoice(response, "category-hero"), recs: findChoice(response, "category-recs"), promo: findChoice(response, "promo-bar"), ``` -------------------------------- ### Product Performance API Response Example Source: https://dy.dev/docs/get-product-performance This is an example of the JSON response structure when calling the getProductsData function. It details product interest (views and purchases) for specified timeframes for each SKU. ```json { "1217282-400": { "productInterest": { "view": { "daily": 1, "twoDays": 1 }, "city": { "view": {}, "purchase": {} } } }, "1217282-600": { "productInterest": { "view": { "daily": 1, "twoDays": 1 }, "city": { "view": {}, "purchase": {} } } } } ``` -------------------------------- ### User Data API Request Example Source: https://dy.dev/reference/userdataapi This example demonstrates how to structure a request to the User Data API for upserting and deleting user data. It includes user identifiers, timestamps, and data payloads. ```json { "requests": [ { "action": "upsert", "cuid": "0c907031b7d6515ce8def68a767272d0ec7225e987c3e0ce70b985c265f318f0", "cuidType": "ihe", "timestamp": "2023-07-02T10:44:44+02:00", "data": { "UserSegments": [ "segment 1", "segment 2" ] } }, { "action": "delete", "cuid": "myuser789", "cuidType": "ihe", "timestamp": "2022-05-24T12:31:09+02:00" } ] } ``` -------------------------------- ### Example POST Request with API Key Source: https://dy.dev/docs/api-keys Shows how to include an API key in the DY-API-Key header for a POST request to the /v2/serve/user/choose endpoint. ```json POST /v2/serve/user/choose DY-API-Key: baadc6ba740a352c9106dc7857a7eb9c Content-Type: application/json {// JSON-formatted request body...} ```