High level guide to implement reviews in Optimizely
Loyalty programs, sponsored by retailers and other businesses, offer rewards, discounts, and other special incentives as a way to attract and retain customers. For eCommerce, loyalty program is a system designed as a seamless part of the customer journey to create a proactive community around your brand and offerings.
In this article we’ll be focusing on the Yotpo Loyalty & Rewards integration with Optimizely.
The Optimizely & Yotpo integration provides brands with full access to loyalty and reviews data that can enhance the precision of customer predictions generated by Optimizely’ data science capability, making campaigns more personal and timely. With this integration, brands will deepen customer relationships and increase lifetime value with loyalty and reviews-driven personalization, creating moments of engagement for shoppers based on data.
To get complete benefits of the article, it is recommended to have understanding / experience of Optimizely CMS and Commerce Project Development
Let's start with the Yotpo account creation.by default, one default store gets created when you sign up. While sign-up you will be asked to select product(s). Make sure to select “Loyalty & Reward”.
After successfully signing up you will be redirected to the Loyalty & Reward Dashboard. Now it's time to set up various programs through “Set up Program” menu options.
For your reference various screens from “Set up Program” the menu are given below:
Set up Program - Rewards
Set up Program - Earning Rule
Set up Program - VIP Tiers
You can refer below link to get deep insights of Yotpo Loyalty Account and Programs set up
https://support.yotpo.com/en/article/set-up-your-yotpo-loyalty-referrals-membership-program-with-a-paid-membership-earning-rule
https://support.yotpo.com/en/loyalty-referrals/installing-yotpo-loyalty-referrals
Now it's time to implement various APIs available for Review with Optimizely. Before moving to the next step. Lets explore below API documentation available from Yotpo.
https://loyaltyapi.yotpo.com/reference/reference-getting-started
Implementing Yotpo Loyalty with Optimizely Commerce
- Create Yotpo Loyalty Service Module Class
This class contains all the settings and implementation code of Yotpo Review API with the CMS / Commerce Application. Refer below sample
====================================================
namespace Loyalty.Yotpo
{
internal class YotpoLoyaltyService: ILoyaltyService
{
private readonly YotpoSettings _settings;
private readonly HttpClient _httpClient;
public YotpoLoyaltyService(YotpoSettings settings, HttpClient httpClient)
{
_settings = settings;
_httpClient = httpClient;
}
public async Task<Result> CreateCustomer(string id, string email, string firstName, string lastName)
{
HttpResponseMessage response;
try
{
var customer = new { };
response = await _httpClient.SendAsync(BuildRequest(customer, "POST", "customers"));
}
catch (Exception ex)
{
//return implementation
}
//return implementation
}
public async Task<Result> GetRedemptionOptions()
{
//implementation of "redemption_options" api
}
public async Task<Result> GetTiers()
{
//implementation of "vip_tiers" api
}
public async Task<Result> GetCustomerDetails(string email, bool withDetails = false)
{
//implementation of "customers?customer_email={HttpUtility.UrlEncode(email)}&with_history={withDetails}" api
}
public async Task<ValueResult<IReadOnlyList<ReferralDto>>> GetReferrals(string email)
{
//implementation of "referral/referrer" api
}
public async Task<Result> Redeem(string email, int redemptionOptionId)
{
//implementation of "redemptions" api
}
public async Task<Result> CreateOrder(OrderDto order)
{
//implementation of "orders" api
}
public async Task<Result> CancelOrder(OrderDto order)
{
//implementation of "refunds" api
}
public async Task<Result> SendReferralLink(string referringEmail, string emailTo)
{
//implementation of "referral/share" api
}
protected override HttpRequestMessage BuildRequest(
string relativeUrl,
HttpMethod method,
string authorization = null,
object payload = null)
{
HttpRequestMessage request =
base.BuildRequest(relativeUrl, method, authorization, payload);
request.Headers.TryAddWithoutValidation("x-guid", _settings.Guid);
request.Headers.TryAddWithoutValidation("x-api-key", _settings.ApiKey);
return request;
}
}
}
====================================================
Once the Service class is ready now it's time to make it available to CMS / Commerce. This can be done using the Optimizely Initialization. This is documented in the Optimizely World and you can refer to this link for more details.
https://docs.developers.optimizely.com/content-cloud/v11.0.0-content-cloud/docs/initialization
Below is the sample example of Initialization Module class
====================================================
namespace Loyalty.Yotpo { [InitializableModule]
public class LoyaltyInit: IConfigurableModule {
public void Initialize(InitializationEngine context) {}
public void Initialize(InitializationEngine context) {}
public void ConfigureContainer(ServiceConfigurationContext context) {
if (context == null) {
throw new ArgumentNullException(nameof(context));
}
context.Services.AddSingleton < ILoyaltyService,
YotpoLoyaltyService > ();
context.Services.AddSingleton < ILoyaltySettings,
YotpoSettings > ();
}
}
}
====================================================
Above code snippet also uses Dependency Injection through the ConfigurationContainer method. Ideally YotpoLoyaltyService should contain implementation code and YotpoSettings should contain Yotpo settings related information, refer below code snippet.
====================================================
namespace Loyalty.Yotpo {
internal class YotpoSettings: ILoyaltySettings,
IHttpSettings {
private readonly IAppSettingsDictionary _appSettings;
public YotpoSettings(IAppSettingsDictionary appSettings) {
_appSettings = appSettings;
}
public string BaseUrl =>_appSettings.GetValue("yotpo:Loyalty:BaseUrl");
public string Guid =>_appSettings.GetValue("yotpo:Guid");
public string ApiKey =>_appSettings.GetValue("yotpo:ApiKey");
public string VipTierName =>_appSettings.GetValue("yotpo:VipTierName");
public string PaidVipTierName =>_appSettings.GetValue("yotpo:PaidVipTierName");
}
}
====================================================
namespace Loyalty.Yotpo
{
internal class YotpoLoyaltyService: ILoyaltyService
{
private readonly YotpoSettings _settings;
private readonly HttpClient _httpClient;
public YotpoLoyaltyService(YotpoSettings settings, HttpClient httpClient)
{
_settings = settings;
_httpClient = httpClient;
}
public async Task<Result> CreateCustomer(string id, string email, string firstName, string lastName)
{
HttpResponseMessage response;
try
{
var customer = new { };
response = await _httpClient.SendAsync(BuildRequest(customer, "POST", "customers"));
}
catch (Exception ex)
{
//return implementation
}
//return implementation
}
public async Task<Result> GetRedemptionOptions()
{
//implementation of "redemption_options" api
}
public async Task<Result> GetTiers()
{
//implementation of "vip_tiers" api
}
public async Task<Result> GetCustomerDetails(string email, bool withDetails = false)
{
//implementation of "customers?customer_email={HttpUtility.UrlEncode(email)}&with_history={withDetails}" api
}
public async Task<ValueResult<IReadOnlyList<ReferralDto>>> GetReferrals(string email)
{
//implementation of "referral/referrer" api
}
public async Task<Result> Redeem(string email, int redemptionOptionId)
{
//implementation of "redemptions" api
}
public async Task<Result> CreateOrder(OrderDto order)
{
//implementation of "orders" api
}
public async Task<Result> CancelOrder(OrderDto order)
{
//implementation of "refunds" api
}
public async Task<Result> SendReferralLink(string referringEmail, string emailTo)
{
//implementation of "referral/share" api
}
protected override HttpRequestMessage BuildRequest(
string relativeUrl,
HttpMethod method,
string authorization = null,
object payload = null)
{
HttpRequestMessage request =
base.BuildRequest(relativeUrl, method, authorization, payload);
request.Headers.TryAddWithoutValidation("x-guid", _settings.Guid);
request.Headers.TryAddWithoutValidation("x-api-key", _settings.ApiKey);
return request;
}
}
}
- A scheduled job is a service performing a task (job) at a given time interval or an administrator can start it manually. By default, Optimizely platform with Optimizely CMS and Optimizely Commerce includes several scheduled jobs. You can develop customized scheduled jobs for specific website purposes. Creation of jobs are provided in details in mentioned articles
https://docs.developers.optimizely.com/content-cloud/v11.0.0-content-cloud/docs/scheduled-jobs
https://docs.developers.optimizely.com/commerce/v13.0.0-commerce-cloud/docs/scheduled-jobs
- For Yotpo Loyalty, Jobs can be created for syncing between Yotpo and Optimizely. Example of synchronization can be for Loyalty Redemption, Order Export from Optimizely to Yotpo Loyalty, Order Returns etc.
To conclude the article in a few words: Optimizely (CMS & Commerce) site(s) can easily make use of Richer Loyalty program of Yotpo.