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.
The Inference phase allows you to apply machine learning by using model-driven recommendations in two key ways:
- Creating and sending automated personalized email campaigns
- 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
- Generate a secure token for accessing your CRM data.
- AWS Lambda for backend processing.
- Amazon Personalize APIs (e.g., PutUsers, PutItems) for model integration.
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
- Familiarity with setting up:
- Programmable Email Modules
- Marketing Emails for product recommendations
- Subscription Types and Campaign Settings
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.
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:
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.
- Code: Copy the code from the GitHub repository and edit the association definition ID on line 33 to query associated “Recommendations” for each contact.
- 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
- Use the HubSpot Tracking Code on your site to monitor user activity.
- Alternatively, use the Tracking Code API to identify visitors, track events, and log page views.
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:
- Workflows & Event-Based Enrollments
- Custom Coded Actions
- Node.js 20.x or higher
- Axios Library
- Lambda Functions
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)
- Set up a Contact-based Workflow with an Object-created trigger.
- Add a Manage Communication Subscription action for enrolled contacts.
- Code: Create a Custom Coded Action to send contact data, using AWS Lambda Authentication to push data to Amazon Personalize’s PutUsers API endpoint (created by the CloudFormation stack in the Training Phase)
- Properties - include Contact properties to send to AWS Personalize
- Age
- Gender
- Properties - include Contact properties to send to AWS Personalize
- Copy the HubSpot Contact Record ID to a custom single-line text property “External ID” via the Copy Property Value action step.
Create Workflow for Purchase Data (HubSpot Deal Checkout Completed → Amazon Personalize)
- Set up a Deal-based Workflow triggered by Property Value Change (e.g., Checkout Completed).
- Code: Build a Custom Coded Action to compile purchase data and structure it for Amazon Personalize.
- Code: Copy the JSON request body from GitHub to ensure it matches AWS requirements.
Create Workflow for Interaction Events (HubSpot Custom Event → Amazon Personalize)
- Configure a Contact-based Workflow triggered by a completed Custom Event (e.g., Add to Cart).
- Code: Create a Custom Coded Action to gather interaction data, standardize it, and send it to Amazon Personalize.
- Delay Step: Add a 1-minute delay before proceeding to fetch recommendations.
- Code: Fetch recommendations using Lambda functions to:
- Retrieve recommendations from Personalize based on the user ID.
- Parse the recommendation results to extract product metadata, such as product names, IDs, and other attributes.
- Code: Store the fetched recommendations in a Custom Object and create records with the relevant contact in HubSpot.
- Associate the recommendations with the relevant contact. The associationTypeId will associate the Contact with the Custom Object for recommendations.
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.
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:
- A private app to interact with your CRM data securely.
- An app card built with React to display recommendations.
- A serverless function that powers backend interactions for the app card.
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:
- A HubSpot account with access to CRM Development Tools (available in public beta).
- Building UI extensions for private apps in a standard HubSpot account requires an Enterprise subscription. However, you can build private apps using projects in developer test accounts for free.
- The HubSpot CLI is installed and configured.
- Install Node.js enabling HubSpot’sd local development tools.
- Familiarity with developer projects within the HubSpot ecosystem.
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:
- Navigate to your project directory.
- You can refer to the project config file and the srcDir field to confirm the directory name containing your project files. For this project, you’ll refer to the src folder.
- Run the following command:
- 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.