Skip to content

Why ML Recommendations Matter: Building a Custom Solution with HubSpot and AWS (Part 2: Inference Phase)

In our first blog post, “Why ML Recommendations Matter: Building a Custom Solution with HubSpot and AWS”, we explored the rising importance of personalized customer experiences in B2C and B2B environments. We introduced a project that demonstrates integrating HubSpot with Amazon Personalize to build a custom recommendation engine, focusing on two key phases: Training and Inference. While the Training phase concentrates on data preparation and establishing foundational model elements, the inference phase uses the trained model to generate actionable, personalized recommendations in HubSpot.

In this post, we shift our focus to the Inference phase. Here, we’ll guide you using the Amazon Personalize model to generate and implement recommendations in HubSpot. This includes automating personalized product recommendations in email campaigns and creating custom CRM card extensions that empower sales reps to leverage these recommendations in real-time.

Solution overview diagram

The Inference phase allows you to apply machine learning by using model-driven recommendations in two key ways: 

  1. Creating and sending automated personalized email campaigns 
  2. Generating recommendations from a CRM app card that your sales and marketing teams can reference when engaging clients 

These tools enable real-time, user-specific recommendations, enhancing customer engagement and driving conversions. This post will guide you through setting up HubSpot assets like custom UI extensions and implementing workflows for personalized interactions, along with tips for maximizing their impact.

To recap the Training phase, we focused on data preparation by structuring key data objects like products, users, and interactions in HubSpot to ensure accurate model training. We also discussed exporting this data through Snowflake or the CSV file to S3 for model training in Amazon Personalize, and we created a serverless API gateway to interact with when generating recommendations. Now, with the trained model, we can create personalized customer experiences in HubSpot.

Prerequisites for the Inference Phase

This guide will help you through the training process to create a recommendation engine that delivers real business value. We encourage you to follow along by referring to the following resources: 

Make sure you’ve completed the Training phase. This includes structuring data objects (e.g., products, users, interactions) in HubSpot and training your model using Amazon Personalize.
Contains all the necessary code samples, detailed instructions, and a complete list of technical prerequisites. Access the GitHub repository for all necessary code samples, detailed instructions, and technical requirements. This includes JavaScript code for custom events, HubSpot serverless functions and an automated CloudFormation stack deployment of Amazon Personalize.
  • HubSpot Account with Developer Access

A HubSpot account with CRM Development Tools access (public beta). Enterprise accounts are required for CRM customizations, but private apps can be built in a developer test account for free.

Programming Tools

  • HubSpot Private App Access Token
AWS Tools

Note: If you followed along during the training phase of this build, these resources should already be established. The Inference phase depends on the running personalize model, which is accessible via the API Gateway, triggering the Lambda functions.

Workflows & Event-Based Enrollments
      • Set up HubSpot workflows to automate data transfer and integrate recommendations with event-based enrollments. Examples include workflows for:
        • Contact data transfer
        • Purchase data processing
        • Interaction event tracking
Marketing Tools in HubSpot

With these resources ready, you’ll be equipped to implement the Inference phase.

Step 3: Create HubSpot Assets for Personalized Recommendations

Before starting this step, please ensure you have completed steps 1 and 2 from our previous blog post on the Training phase. This step will focus on setting up essential assets within HubSpot to bring your personalized recommendations to life. This includes configuring automated marketing emails, tracking custom events, and building workflows to facilitate data transfer between HubSpot and Amazon Personalize. Below, we will guide you through the process of configuring these assets to ensure seamless delivery and integration of recommendations across all customer touchpoints.

1. Create a Custom Object for Product Recommendation

Personalized product recommendations from Amazon Personalize will be stored and managed within a HubSpot Custom Object named “Product Recommendations”. This Custom Object will facilitate data for marketing email campaigns and the HubSpot CRM App Card to impact conversions and revenue. Each Product Recommendation record will be associated with a HubSpot Contact to allow HubSpot Users to view Recommendations within a Contact record.

To build the Product Recommendation Custom Object within HubSpot, execute the following Postman script.

2. Creating Marketing Emails with Product Recommendations

One of the most effective ways to deliver personalized recommendations is through automated emails incorporating customized content based on user interactions and preferences. For instance, shown below is an example of personalized recommendations for a specific contact.

UI example of personalize recommendations for a specific contact

Once you’ve created these personalized recommendations, you can use them to engage with those contacts through scheduled emails or automated workflows. Here’s an example of what a personalized email might look like: 

Example of personalized email

To help get you started, here’s a guide for setting up a programmable email module in HubSpot:

Build a Programmable Email Module

  • Navigate to Marketing > Design Manager and create a new file of Type = Module.
  • Set the Module usage to Emails and Content Scope to Local.
  • Enable the setting for “Use module for programmable email” to allow custom code.
  • Add fields and structures required for the email content in the code section.

Example of added fields

  • Save and Publish the module.

Set Up the Product Recommendations Email

  • Go to Marketing > Email and create a new email with Type = Automated Email.
  • Choose a suitable template for your marketing email.
  • Add marketing content that highlights Product Recommendations with personalization from the Contact Object.
  • Add the programmable module into the email to dynamically load product recommendations.
  • Configure Settings such as Subscription Type, Subject Line, and Campaign.
  • Save and publish the email ready for use in your Workflow Automation.

3. Tracking Customer Interactions with Custom Events

Tracking customer interactions on your platform is essential to leverage Amazon Personalize effectively. This data is captured as custom events in HubSpot and enables detailed behavioral insights. Here’s how to set up custom events:

Implement HubSpot Tracking Code

Set Up JavaScript for Specific Events

  • Define and create custom events such as Add to Cart or Checkout that map to customer behavior and interactions.
  • Copy the JavaScript code from GitHub and insert it into your application’s code, such as when clicking the Add to Cart button.

4. Automating Data Transfer with Workflow Automation

With the right workflows, you can automate the transfer of CRM data from HubSpot to Amazon Personalize in real time and manage recommendation retrieval. Here’s how to configure workflows for seamless integration:

Setting Up Workflows for Data Transfer to Amazon Personalize

  • HubSpot’s Operations Hub Professional supports custom-coded actions and programmable automation. Below are key workflows for user, interaction, and purchase data transfers.

Resources Required for this Section:

To implement this part of the integration, visit the GitHub repository to access the pre-built code snippets and more detailed setup instructions. The repository includes examples for constructing the event data and API requests.

Create Workflow for Contact Data (HubSpot Contact → Amazon Personalize)

Create Workflow for Purchase Data (HubSpot Deal Checkout Completed → Amazon Personalize)

Create Workflow for Interaction Events (HubSpot Custom Event → Amazon Personalize)

By following these steps, you will create an interconnected system that effectively tracks customer behavior, generates real-time recommendations, and presents personalized content through emails and CRM views. This integration enhances the customer experience and empowers your sales and marketing teams with actionable insights, making every interaction more meaningful and targeted.

Step 4: Utilize Recommendations in a HubSpot App Card and Automated Emails Campaigns

UI customization in HubSpot’s CRM is a game-changer that drives efficient sales processes. Sales reps gain efficiency by having the right contextual and action-oriented data in a unified system. Providing reps with personalized outreach and product recommendations will help them provide the right pitch for a prospect. While smaller transactions may be handled through automation, inside sales teams can benefit by delivering high-value customers personalized attention.

The personalization engine you’ve built can be seamlessly integrated into HubSpot’s CRM, allowing reps to take meaningful actions based on product recommendations. This is where HubSpot’s CRM App cards shine. These extensions—micro-apps hosted on HubSpot with a React frontend and Node.js backend—enable developers to build dynamic tools directly within the CRM interface.

With this setup, sales reps can:

  • View tailored product recommendations directly within a contact’s record.
  • Take immediate action, such as opening a deal or sending a recommendation email, all with a single click.

App card example

This streamlined approach combines automation with human interaction to maximize the effectiveness of your sales process.

Getting Started with HubSpot’s Developer Tools

To help you implement this solution, HubSpot offers a Getting Started Project Template. This project includes all the building blocks you need:

This setup provides a quick start for developers, enabling them to focus on creating impactful CRM customizations rather than dealing with setup complexities.

Resources Required for this Section:

Before diving in, ensure you have the following ready:

Testing and Iterating Locally with the HubSpot CLI

The HubSpot CLI makes it easy to test and iterate your project locally. Follow these steps to get started:

hs project dev
  • Follow the prompts to start the development server and view your app in action.

This approach lets you make quick updates, preview changes in real-time, and ensure your solution is ready for production

Summary

The Inference Phase is where the true value of machine learning integration shines. By connecting Amazon Personalize with HubSpot’s CRM and marketing tools, businesses can unlock the potential of raw data, transforming it into meaningful, actionable insights that elevate customer engagement and drive sales. From personalized email campaigns to real-time recommendations in CRM records, this approach offers a powerful way to deliver tailored experiences at every touchpoint.

As you implement these steps, remember that personalization is a journey filled with possibilities. Continuously monitor and refine your model’s performance, gather feedback from your sales and marketing teams, and iterate on workflows to ensure your recommendations remain relevant and impactful. With this strong foundation, you are not just meeting customer expectations but exceeding them, one recommendation at a time.

Stay tuned for the next part of this series, where we will explore enhancements to optimize your recommendation engine.

Authors

Screenshot 2024-10-01 at 10.04.14 AM-1  Robert Ainslie, Manager, Solution Architecture, HubSpot
Screenshot 2024-10-01 at 10.05.15 AM Amit Das, Senior Solutions Architect, HubSpot
SteveMiller Steve Miller, Manager, Interim Engineering, Veracross