Wiki source code of Recommendations
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | (% class="lead" %) | ||
| 2 | Product recommendation functionality allows you to include products selected by one of the supported algorithms based on customer preferences directly in message content. | ||
| 3 | |||
| 4 | {{info}} | ||
| 5 | Product recommendation functionality is only available when integration with the [[Loymax AI>>doc:Main.General_information.Loymax_AI.WebHome]] module is configured. | ||
| 6 | {{/info}} | ||
| 7 | |||
| 8 | (% class="box" %) | ||
| 9 | ((( | ||
| 10 | **Contents:** | ||
| 11 | |||
| 12 | {{toc depth="3" start="2"/}} | ||
| 13 | ))) | ||
| 14 | |||
| 15 | The general recommendation generation process works as follows: | ||
| 16 | |||
| 17 | 1. The marketer creates a recommendation in the Loymax Platform. | ||
| 18 | 1. The marketer inserts the recommendation code into a message. | ||
| 19 | 1. When generating the message, Loymax Smart Communications sends a request to [[Loymax AI>>doc:Main.General_information.Loymax_AI.WebHome]] for recommended products. | ||
| 20 | 1. Loymax AI returns an array of products generated using the specified algorithm. | ||
| 21 | 1. Loymax Smart Communications sends a personalized message containing the recommendations. | ||
| 22 | |||
| 23 | == Creating recommendations using Loymax AI algorithms == | ||
| 24 | |||
| 25 | To view the list of created recommendations, go to the **Recommendations** section in the left-hand panel. | ||
| 26 | |||
| 27 | |(% style="border-color:#ffffff; text-align:center" %){{lightbox image="recommendations.png" width="660"/}} | ||
| 28 | |||
| 29 | The following actions are available in the **Recommendations** section: | ||
| 30 | |||
| 31 | * Create a new recommendation ([[image:1.png]]). | ||
| 32 | * Sort the table by any column ([[image:2.png]]). | ||
| 33 | * Edit, copy, or delete a recommendation ([[image:3.png]]). You can also edit a recommendation by clicking its code or name. | ||
| 34 | |||
| 35 | Clicking the button to create a new recommendation or edit an existing one opens the recommendation editing window. | ||
| 36 | |||
| 37 | |(% style="border-color:white; width:70%" %)((( | ||
| 38 | Fill in the required recommendation fields: | ||
| 39 | |||
| 40 | * **Recommendation code** — a short code used to insert recommendations into messages. | ||
| 41 | * **Recommendation name** — a human-readable name displayed in the list of configured recommendations. | ||
| 42 | * **Recommendation algorithm** — select the desired algorithm from the list: | ||
| 43 | ** [[Popular products>>doc:Main.General_information.Loymax_AI.Commercial_recommendations.WebHome||anchor="H41043B43343E44043844243C2241F43E43F44343B44F44043D44B43544243E43243044044B22"]]. Algorithm that recommends the most popular products from the entire catalog, regardless of the customer’s history. | ||
| 44 | ** [[Popular products in category>>doc:Main.General_information.Loymax_AI.Commercial_recommendations.WebHome||anchor="H41043B43343E44043844243C2241F43E43F44343B44F44043D44B43544243E43243044044B43243A43044243543343E44043843822"]]. Algorithm that recommends the most popular products from categories the customer has shown interest in (viewed, purchased, or ordered). | ||
| 45 | ** [[Similar products>>doc:Main.General_information.Loymax_AI.Commercial_recommendations.WebHome||anchor="H41043B43343E44043844243C2241F43E44543E43643843544243E43243044044B22"]]. Algorithm that recommends products similar to those the customer has shown interest in. | ||
| 46 | ** [[Frequently bought together>>doc:Main.General_information.Loymax_AI.Commercial_recommendations.WebHome||anchor="H41043B43343E44043844243C2242143E43243C43544144243D44B43543F43E43A44343F43A43822"]]. Algorithm that recommends products frequently purchased together with products the customer has shown interest in. | ||
| 47 | ** [[Personalized product recommendations>>doc:Main.General_information.Loymax_AI.Commercial_recommendations.WebHome||anchor="H41043B43343E44043844243C2241F43544044143E43D43043B44C43D44B43544243E43243044043D44B43544043543A43E43C43543D43443044643843822"]]. Algorithm that predicts a customer’s future purchases based on their history and recommends products accordingly. | ||
| 48 | ** [[Manual recommendations>>||anchor="H41D43044144244043E43943A43044044344743D44B44544043543A43E43C43543D434430446438439"]]. Algorithm that recommends products based on category-matching rules without using the Loymax AI module. | ||
| 49 | |||
| 50 | Configure the recommendation parameters. The available parameters depend on the selected algorithm. | ||
| 51 | |||
| 52 | * **Number of recommendations** — the number of products Loymax AI will return. | ||
| 53 | * **Calculate based on** — the source from which Loymax Smart Communications will take products (for calculating recommendations using the [[Frequently bought together>>doc:Main.General_information.Loymax_AI.Commercial_recommendations.WebHome||anchor="H41043B43343E44043844243C2242143E43243C43544144243D44B43543F43E43A44343F43A43822"]] and [[Similar products>>doc:Main.General_information.Loymax_AI.Commercial_recommendations.WebHome||anchor="H41043B43343E44043844243C2241F43E44543E43643843544243E43243044044B22"]] algorithms) or categories (for calculating recommendations using the [[Popular products in category>>doc:Main.General_information.Loymax_AI.Commercial_recommendations.WebHome||anchor="H41043B43343E44043844243C2241F43E43F44343B44F44043D44B43544243E43243044044B43243A43044243543343E44043843822"]] algorithm). | ||
| 54 | )))|(% style="border-color:white; text-align:center; width:30%" %){{lightbox image="recommendation_edit.png" width="400"/}} | ||
| 55 | |||
| 56 | == Creating manual recommendations == | ||
| 57 | |||
| 58 | |(% style="border-color:white; width:70%" %)((( | ||
| 59 | Manual recommendations differ from all other algorithms in that the calculation is performed entirely within Loymax Smart Communications. Manual recommendations are calculated once per day according to the configured parameters. | ||
| 60 | |||
| 61 | When calculating manual recommendations, the system checks the specified source (**Calculate based on** field) for products belonging to the defined **Target category**. Then, the system selects products from **Recommended categories** that most frequently appear together with the target product in receipts. The algorithm returns N of the most popular products, where N is the value set in the **Number** field. | ||
| 62 | |||
| 63 | Recommendations can be further restricted: if **Advanced matching settings** are defined, the algorithm will only suggest products whose parameter values match those of the target product. | ||
| 64 | |||
| 65 | The following settings are available for manual recommendations: | ||
| 66 | |||
| 67 | * **Recommend products based on region** ([[image:1.png]]). Depending on this setting, recommended products will be filtered by the **Region** field either in the [[customer profile>>doc:Main.Smart_Communications.SMC_Use.Customers.All_clients.WebHome||anchor="H41F44043E44443843B44C43A43B43843543D442430"]] or in the customer’s latest web session. | ||
| 68 | * **Calculation period** ([[image:2.png]]). The period over which receipts will be analyzed to identify products most frequently purchased together with the target products. | ||
| 69 | * **Calculate based on** ([[image:3.png]]). As with other algorithms, this is the source from which Loymax Smart Communications retrieves target products. | ||
| 70 | * **Target category** ([[image:4.png]]). The category containing products for which recommendations will be calculated. To add a target category, click **+ Add match** in the bottom-left corner of the window. | ||
| 71 | * **Recommended category** ([[image:5.png]]). The category containing products that will be recommended. Multiple recommended categories can be selected for a single target category. To add a recommended category, click **+ Add category**. | ||
| 72 | * **Number** ([[image:5.png]]). The number of products from this recommended category the algorithm will return. This number is set separately for each recommended category. | ||
| 73 | * **Advanced matching settings** ([[image:6.png]]). Click **+ Add match** in the right part of the window to add a field by which the algorithm’s output should be filtered. Advanced matching settings are defined separately for each target category (i.e., they apply to all recommended categories). | ||
| 74 | |||
| 75 | {{success}} | ||
| 76 | * For fields with numeric data types and the **date** data type, the **Exact match** checkbox is available. If enabled, a product will only be recommended if its value exactly matches the corresponding attribute of the target product. | ||
| 77 | * For fields with **string** and **boolean** data types, exact matching is always required. | ||
| 78 | * If the **Exact match** checkbox is disabled, a product will be included in recommendations if its attribute value differs from the target product’s value by no more than 15%. | ||
| 79 | {{/success}} | ||
| 80 | )))|(% style="border-color:white; text-align:center; width:30%" %){{lightbox image="recommendation_manual.png" width="400"/}} | ||
| 81 | |||
| 82 | == Inserting recommendations into messages == | ||
| 83 | |||
| 84 | To display recommendations in messages, you must use [[template engine>>doc:Main.Smart_Communications.SMC_Use.Mass_mailings.Template_builder.WebHome]] constructs. | ||
| 85 | |||
| 86 | Consider an example of adding recommendations to a message. An email campaign needs to be sent to customers with recommendations using the [[Frequently bought together>>doc:Main.General_information.Loymax_AI.Commercial_recommendations.WebHome||anchor="H41043B43343E44043844243C2242143E43243C43544144243D44B43543F43E43A44343F43A43822"]] algorithm (a recommendation with code ##sov_pok## has been created in the system for this purpose). For customers without sufficient purchase history, recommendations will be provided using the [[Popular products>>doc:Main.General_information.Loymax_AI.Commercial_recommendations.WebHome||anchor="H41043B43343E44043844243C2241F43E43F44343B44F44043D44B43544243E43243044044B22"]] algorithm (a recommendation with code ##popular## has been created in the system for this purpose). | ||
| 87 | |||
| 88 | The email layout assumes displaying 3 to 9 product cards—1 to 3 rows of 3 cards each. Only products available for ordering in the online store should be recommended. Additionally, the product price must be displayed in the message, and if the price has changed, both the old and new prices should be shown. | ||
| 89 | |||
| 90 | 1. Define a variable ##Rec## and assign it an array of Product (##product##) objects selected by the [[Frequently bought together>>doc:Main.General_information.Loymax_AI.Commercial_recommendations.WebHome||anchor="H41043B43343E44043844243C2242143E43243C43544144243D44B43543F43E43A44343F43A43822"]] algorithm. If the customer hasn’t made enough purchases, fall back to the [[Popular products>>doc:Main.General_information.Loymax_AI.Commercial_recommendations.WebHome||anchor="H41043B43343E44043844243C2241F43E43F44343B44F44043D44B43544243E43243044044B22"]] algorithm. | ||
| 91 | |||
| 92 | {{code language="twig"}} | ||
| 93 | {% set Rec=client.recommendations.sov_pok %} | ||
| 94 | {% if not Rec or Rec|length < 3 %} | ||
| 95 | {% set Rec=client.recommendations.popular %} | ||
| 96 | {% endif %} | ||
| 97 | |||
| 98 | {{/code}} | ||
| 99 | |||
| 100 | (% start="2" %) | ||
| 101 | 1. Filter the array of recommended products to keep only those available for purchase in the online store (the boolean custom [[field>>doc:Main.Smart_Communications.SMC_Use.Settings_SC.Data_field.WebHome]] ##eComAvailable## equals ##true##). To do this, define a variable ##filteredRec## to store the filtered recommendations. | ||
| 102 | 1. No more than 9 products (three rows of three) should be displayed in the message. Define a variable ##count_recs## as a counter: each time a product is added to the filtered recommendations array, increment the counter by 1. | ||
| 103 | 1. Iterate through all products and add to the array only those that haven’t already been added (in case Loymax AI returned the same product twice) and that are available for ordering in the online store. Also, check the counter value and add the product only if fewer than 9 recommendations have been collected. | ||
| 104 | |||
| 105 | {{code language="twig"}} | ||
| 106 | {% set count_recs=0 %} | ||
| 107 | {% set filteredRec=[] %} | ||
| 108 | {% for product in Rec %} | ||
| 109 | {% if product not in filteredRec and product.eComAvailable=='Y' and count_recs < 9 %} | ||
| 110 | {% set filteredRec=filteredRec|merge([product]) %} | ||
| 111 | {% set count_recs=count_recs + 1 %} | ||
| 112 | {% endif %} | ||
| 113 | {% endfor %} | ||
| 114 | {{/code}} | ||
| 115 | |||
| 116 | (% start="5" %) | ||
| 117 | 1. Split the filtered recommendations into groups of three. | ||
| 118 | 1. If the filtering process results in a number of suitable products not divisible by 3, the last group will contain fewer than 3 products (e.g., 7 = 3 + 3 + 1). Check and display only those groups containing exactly three products. | ||
| 119 | 1. For each product, display its name and image. | ||
| 120 | |||
| 121 | {{code language="twig"}} | ||
| 122 | {% for batch in filteredRec|batch(3) %} | ||
| 123 | {% if batch|length==3 %} | ||
| 124 | {% for recommendation in batch %} | ||
| 125 | {{ recommendation.name }} | ||
| 126 | {{ recommendation.image_url }} | ||
| 127 | {{/code}} | ||
| 128 | |||
| 129 | (% start="8" %) | ||
| 130 | 1. Next, implement the following logic: | ||
| 131 | 1*. If the product price has changed (current online store price and old price fields are not equal), display both the old and new prices; | ||
| 132 | 1*. If the price hasn’t changed and the online store price field is populated, display the current price; | ||
| 133 | 1*. If the online store price field is empty, display "Price to be confirmed." | ||
| 134 | |||
| 135 | {{code language="twig"}} | ||
| 136 | {% if recommendation.priceim and recommendation.oldprice and recommendation.priceim != recommendation.oldprice %} | ||
| 137 | Price: {{ recommendation.priceim }} | ||
| 138 | Old price: {{ recommendation.oldprice }} | ||
| 139 | {% elseif recommendation.priceim %} | ||
| 140 | Price: {{ recommendation.priceim }} | ||
| 141 | {% else %} | ||
| 142 | Price to be confirmed | ||
| 143 | {% endif %} | ||
| 144 | {% endfor %} | ||
| 145 | {{/code}} | ||
| 146 | |||
| 147 | The final construct will look like this: | ||
| 148 | |||
| 149 | {{code language="twig"}} | ||
| 150 | {% set Rec=client.recommendations.sov_pok %} | ||
| 151 | {% if not Rec or Rec|length < 3 %} | ||
| 152 | {% set Rec=client.recommendations.popular %} | ||
| 153 | {% endif %} | ||
| 154 | {% set count_recs=0 %} | ||
| 155 | {% set filteredRec=[] %} | ||
| 156 | {% for product in Rec %} | ||
| 157 | {% if product not in filteredRec and product.eComAvailable=='Y' and count_recs < 9 %} | ||
| 158 | {% set filteredRec=filteredRec|merge([product]) %} | ||
| 159 | {% set count_recs=count_recs + 1 %} | ||
| 160 | {% endif %} | ||
| 161 | {% endfor %} | ||
| 162 | {% for batch in filteredRec|batch(3) %} | ||
| 163 | {% if batch|length==3 %} | ||
| 164 | {% for recommendation in batch %} | ||
| 165 | {{ recommendation.name }} | ||
| 166 | {{ recommendation.image_url }} | ||
| 167 | {% if recommendation.priceim and recommendation.oldprice and recommendation.priceim != recommendation.oldprice %} | ||
| 168 | Price: {{ recommendation.priceim }} | ||
| 169 | Old price: {{ recommendation.oldprice }} | ||
| 170 | {% elseif recommendation.priceim %} | ||
| 171 | Price: {{ recommendation.priceim }} | ||
| 172 | {% else %} | ||
| 173 | Price to be confirmed | ||
| 174 | {% endif %} | ||
| 175 | {% endfor %} | ||
| 176 | {% endif %} | ||
| 177 | {% endfor %} | ||
| 178 | {{/code}} | ||
| 179 | |||
| 180 | (% class="box" %) | ||
| 181 | ((( | ||
| 182 | **See also:** | ||
| 183 | |||
| 184 | * [[Product recommendation algorithms>>doc:Main.General_information.Loymax_AI.Commercial_recommendations.WebHome]] | ||
| 185 | * [[Message template engine>>doc:Main.Smart_Communications.SMC_Use.Mass_mailings.Template_builder.WebHome]] | ||
| 186 | ))) |