Welcome! This is my personal blog about Web technologies, software development, open source and other related topics
The ideas and opinions expressed here are solely mine and don't represent those of others, either individuals or companies.The code snippets or references to software products or analogous are to be used without any warranty of any kind. If you enjoy the content, feel free to share it and re-use it as long as you provide a link to the original post.
In the session event you should be able to see the Purchase Complete event with the Order Number where the customer completed the checkout.
This should help to get the revenue earned.
cURL code snippet-
curl --location -g --request GET 'https://api.boxever.com/v1.2/event/create.json?client_key=<<Client Key>>&message={"channel":"WEB","type":"CHECKOUT","language":"EN","currency":"GBP","page":"home page","pos":"pastoral-witty-grill","browser_id":"7ed103bd-08c2-47f4-8f69-91141ca3200d","status":"PURCHASED","reference_id":"ORDER_1"}'
C# code snippet-
var client = new RestClient("https://api.boxever.com/v1.2/event/create.json?client_key=<<Client Key>>&message={\"channel\":\"WEB\",\"type\":\"CHECKOUT\",\"language\":\"EN\",\"currency\":\"GBP\",\"page\":\"home page\",\"pos\":\"pastoral-witty-grill\",\"browser_id\":\"7ed103bd-08c2-47f4-8f69-91141ca3200d\",\"status\":\"PURCHASED\",\"reference_id\":\"ORDER_1\"}");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
See how to create a browser id and Add Event before a confirm event is sent.
CONFIRM Event
Search Customer by browserid or Name.
You should be able to see the customer Online at that point odf instance
Click on Timeline and View Session details
Get the session details and should see the Order Confirmed event
Clieck on the settings icon to see more details-
cURL code snippet-
curl --location -g --request GET 'https://api.boxever.com/v1.2/event/create.json?client_key=<<Client Key>>&message={"channel":"WEB","type":"CONFIRM","language":"EN","currency":"GBP","page":"home page","pos":"pastoral-witty-grill","browser_id":"7ed103bd-08c2-47f4-8f69-91141ca3200d","product":[{"item_id":"EXACT_90"}]}'
C# code snippet-
var client = new RestClient("https://api.boxever.com/v1.2/event/create.json?client_key=<<Client Key>>&message={\"channel\":\"WEB\",\"type\":\"CONFIRM\",\"language\":\"EN\",\"currency\":\"GBP\",\"page\":\"home page\",\"pos\":\"pastoral-witty-grill\",\"browser_id\":\"7ed103bd-08c2-47f4-8f69-91141ca3200d\",\"product\":[{\"item_id\":\"EXACT_90\"}]}");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
function SubscribeNewsletter(){
let email = document.getElementById("newsletteremail");
console.log(email)
if (email.value == "") {
alert("Ensure you input a value in both fields!");
} else {
// perform operation with form input
var request = new XMLHttpRequest();
request.open('POST', 'https://api.sitecoresend.io/v3/subscribers/{maillist}/subscribe.json?apikey={apikey}');
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestHeader('Accept', 'application/json');
request.onreadystatechange = function () {
if (this.readyState === 4) {
console.log('Status:', this.status);
console.log('Headers:', this.getAllResponseHeaders());
console.log('Body:', this.responseText);
}
};
var body = {
'Name': 'Sandeep Pote',
'Email': email.value,
'HasExternalDoubleOptIn': false
};
request.send(JSON.stringify(body));
email.value = "";
alert("User subscribed to newsletter")
}
};
function UnSubscribeNewsletter(){
let email = document.getElementById("optout-newsletteremail");
console.log(email)
if (email.value == "") {
alert("Ensure you input a value in both fields!");
} else {
// perform operation with form input
var request = new XMLHttpRequest();
request.open('POST', 'https://api.sitecoresend.io/v3/subscribers/{maillist}/unsubscribe.json?apikey={apikey}');
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestHeader('Accept', 'application/json');
request.onreadystatechange = function () {
if (this.readyState === 4) {
console.log('Status:', this.status);
console.log('Headers:', this.getAllResponseHeaders());
console.log('Body:', this.responseText);
}
};
var body = {
'Email': email.value,
};
request.send(JSON.stringify(body));
email.value = "";
alert("User subscribed to newsletter")
}
};
Looks simple, but you might see when the user un-subscribed from a mailing list the user is never sent a mail from other mailing list or any other transactional mail.
You can force close event to test Abandon Cart. This works only in non-prod environments.
Assumption- An identified guest which is active and has added products in cart.
If you are corectly tracking you should see in the timeline Session and event a Product been added.
So whilst developing if you want to force close this session, since you might not want to wait for 20 minutes for session to expire or whatever time is set to expire the session, you can force close the session to see or perform the next steps if the cart is been abandoned.
The force close event can be triggered by providing message type as FORCE_CLOSE in the payload.
Send the payload to this endpoint. For more details on what should be the apiEndpoint and client key see this blog
var browser_id = pm.environment.get("browserId") -- browser id
var pointOfSale = pm.environment.get("PointOfSale") -- point of sale
var message = {
"channel": "WEB",
"type": "FORCE_CLOSE",
"language": "EN",
"currency": "GBP",
"page": "home page",
"pos": pointOfSale,
"browser_id": browser_id
}
postman.setEnvironmentVariable("message", JSON.stringify(message));
Since the session is now closed we can see the Abandoned Revenue. Further reminder mails can be sent to user to complete the purchase on the abandoned cart.
Load the data in json file. Note that the above is a single row in a json and repeat the rows to upload multiple guets. This is not a json formatted file and should not have “,” to seperate rows as normally json file has. Highlighted email is important to identify the customer and add/update the extended data. This depends on the rule setup for your environment to identify the customer.
gzip the json file to upload
Example-
tar -czvf guest-upload.gz .\guest-upload.json
Generate MD5 File Checksum
Upload the gzip file to generate the check sum on this url –
Ensure the website is configured and verified before using the automation. See this blog. For this blog post I am using – https://moosend.vercel.app/
Create automation using Abandoned Cart automation recipe
Navigate to Automation link and create new automation using recipe-
Select Abandoned cart recipes-
Will be shown the Abandoned Cart Workflow-
Choose Trigger option-
Select- Trigger every time option
Select your website from dropdown and Save. Only verified website will be visible here. You may also choose all sites.
Open wait operation-
For testing I have selected 5 minutes. Ideally this can be few hours/days as per the requirement or enter specific date. By default it is 45 minutes. Enter the wait time and Save.
Setup the filter
Select apply this filter to mailing list. I have selected the email list of the site, you may select different list.
Enter the product if you wish to or leave empty.
Click on “Add a collection”.
Select the time if the product is not purchased for certain time. I have entered 6 minutes. Enter the details and Save.
Select “Added a Product To Cart” and filter value. In this I have added product “Americano”.
Select timer and enter the wait time to 6 minutes and Save
Select the action
In this case Send the mail to user if the product is not purchased in selected time.
Select Send Mail campaign-
Enter the subject, From address, mail body. Select Emails per day. Save once this option is filled.
Activate the “Abandoned Cart” automation-
Automation List with activated
Once the automation configuration is complete will now add product to cart. the product name here is “Americano” as selected in filter.
In the installation script you can find the details on how to add the product to cart.
function addToCart(){
// mandatory - a unique code for the product, like its SKU
var itemCode = 'Americano';
// mandatory - the name / title of this product
var itemName = 'Iced Americano';
// mandatory - the image url of this product
var itemImage = 'http://your.store/product-color-blue.jpg';
// mandatory - the price of this product
var itemPrice = 10.25;
// mandatory - the url to get to the relevant product page
var itemUrl = 'http://your.store/product-101';
// mandatory
var itemQuantity = 1;
// mandatory - the total price for purchasing the given quantity of this product
var itemTotalPrice = 10.25;
// optional - the category of this product
var itemCategory = 'Drinks';
// optional - the manufacturer, brand name or company / owner of this product (if any)
var itemManufacturer = 'Acme Co';
// optional - the supplier of this product (if any)
var itemSupplier = 'Supplier Co';
// you can add custom properies and later use them in segmentations or automations
// You can track things like the color or the sze of the t-shirt in this case
var extraProps = {'flavor': 'Chocolate', 'type': 'Iced'};
// Tracking add to cart events with mandatory arguments
mootrack('trackAddToOrder', itemCode, itemPrice, itemUrl, itemQuantity, itemTotalPrice);
alert("Added to cart event fired");
}
Hook the Add to cart to button-
<button class="button" onclick="addToCart()">Add to cart</button>
The site looks like this with the “Add To Cart” button
Website confirm the event was triggered.
In the automation list you can see the automation been Triggerd-
Once this is triggered you can see the next operation Wait for 5 minutes-
A mail should be triggerd after 6 minutes. Since the product is still in cart and not purchased.
After 5 minutes all the actions should be triggered.
Once all the actions are triggered should receive the mail-
Thats it for this blog. We have managed to trigger a automation event and send themail to the users who have product in the cart and not purchased e.e. Abandoned Cart.
Sitecore Send website tracking service enables to collect data and makes it available for users. It uses cookie-based technology to track data on end-user page visits, product view, add to cart and purchase.
Add website to Sitecore Send
Pre-requisite-
You need to have a website up and running. this can be a simple HTML site or you can choose any other web techology with any Fronetend framework like nextjs, react or jquery etc.
I have created a simple site and hosted using vercel – e.g.:- https://moosend.vercel.app/
To add a website to Sitecore Send –
Navigate to Account –> Websites or New Website option
List of Websites-
Should display list of Websites already configured and if its verified.
Add Website-
On this page enter your website url- https://moosend.vercel.app/
Once this is submitted it should show the Website Id alond with Connection Script. Website Id is required to add this in script to start tracking.
The website list should show the newly added website which should be in unverfied state-
Connect Website
Navigate to Install connection script option. Install button should show the script that is require to add to your website
Copy this script to you website head section, this may be different for you site –