Skip to content

algolia-samples/email-recommendations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Email recommendations

This sample app shows how to leverage Algolia Search and Algolia Recommend to display product recommendations in emails. Showing recommendations is a great way to engage your customers at various stages of their journey before and after visiting your site.

This sample app comes with the following recommendation models:

  • A customer browsed a category: recommend best rated products from that category. This recommendation model uses Algolia's Faceting feature.
  • A customer just bought a product: recommend products that are frequently bought together. This recommendation model uses Algolia Recommend to train a machine-learning algorithm based on which products users often buy together.
  • A customer just bought a product: recommend related products. This model also leverages Algolia Recommend to train a machine-learning algorithm to find products that are similar.
  • A customer has an existing user profile: recommend products that match their affinities. This model uses Algolia Recommend and Personalization.

A flowchart of the email recommendations sample application

Features

This sample app comes with the following features:

  • A rock-solid base email template with Cerberus
  • A rich and powerful templating language with Nunjucks
  • Three different email templates for different moments of the customer's journey (pre-order, post-order, re-engagement)
  • Four different models for recommended products with Algolia Recommend and faceting

How to run this sample app locally

This sample app implements one server in the following programming language:

The client is a single HTML page.

1. Clone this repository

git clone https://github.com/algolia-samples/email-recommendations

Copy the file .env.example to the directory of the server you want to use and rename it to .env. For example, to use the Node implementation:

cp .env.example server/node/.env

2. Set up Algolia

To use this sample app, you need an Algolia account. If you don't have one already, create an account for free. Note your Application ID.

In the .env file, set the environment variables ALGOLIA_APP_ID:

ALGOLIA_APP_ID=<replace-with-your-algolia-app-id>

3. Create your Algolia index and upload data

After you set up your Algolia account and Algolia application, create and populate an index.

To upload your data, you can use the Algolia dashboard or use on of Algolia's API clients.

After creating the index and uploading the data, set the environment variables ALGOLIA_INDEX_NAME and ALGOLIA_API_KEY in the .env file:

ALGOLIA_INDEX_NAME=<replace-with-your-algolia-index-name>
ALGOLIA_API_KEY=<replace-with-your-algolia-api-key>

4. (Optional) Configure an email sending provider

With this sample app, you can send the preview to your email address. We provide a minimal working example with SendGrid as email provider.

In order to use SendGrid, you need to set the environment variables SENDGRID_API_KEY and SENDGRID_FROM_EMAIL in the .env file:

SENDGRID_API_KEY=<replace-with-your-sendgrid-api-key>
SENDGRID_FROM_EMAIL=<replace-with-sendgrid-from-email>

5. Follow the instructions in the server directory

The server directory has a file with instructions:

For example, to run the Node implementation of the server, follow these steps:

cd server/node # there's a README in this folder with instructions
npm install
npm start

Contributing

This sample app is open source and welcomes contributions. All contributions are subject to our Code of Conduct.

Authors