How to Trigger Retargeting Campaigns Based on CRM Updates Using Automation Workflows

admin1234 Avatar

## Introduction

Retargeting campaigns are vital for marketing teams to re-engage leads and customers by delivering personalized ads or messages based on their behavior and status in the sales funnel. However, manually monitoring CRM updates and triggering retargeting efforts can be slow and error-prone, leading to missed opportunities and inefficiencies.

This article presents a step-by-step guide to building an automation workflow that triggers retargeting campaigns directly from CRM updates. The automation ensures that any relevant changes in a lead or customer’s CRM record immediately activate retargeting efforts across platforms such as Facebook Ads, Google Ads, or third-party marketing tools.

This approach benefits marketing teams by streamlining campaign management, reducing manual tasks, and improving the speed and accuracy of targeted advertising.

## Tools and Services Integrated

– **CRM Platform:** HubSpot (widely used and offers robust APIs)
– **Automation Tool:** n8n (open-source workflow automation tool)
– **Ad Platforms:** Facebook Marketing API and Google Ads API
– **Optional:** Slack for notifications

## Workflow Overview

The automation workflow triggers every time an update occurs to contact properties in HubSpot CRM (e.g., lifecycle stage, lead status, or custom fields). It evaluates whether the update qualifies the contact for a retargeting campaign and updates or creates custom audiences or remarketing lists on Facebook and Google Ads accordingly.

### Trigger to Output
1. Trigger: HubSpot contact update webhook
2. Retrieve contact details
3. Evaluate conditions (e.g., lifecycle stage changed to ‘Marketing Qualified Lead’)
4. Update or create custom audience in Facebook Ads API
5. Update or create remarketing list in Google Ads API
6. Optional: Send Slack notification to marketing team

### Benefits
– Immediate campaign adjustments as soon as CRM data changes
– Data-driven retargeting that reflects the current status of each lead
– Reduced manual workload for marketing operations

## Step-by-Step Technical Tutorial Using n8n

### Prerequisites
– HubSpot account with API access and webhook creation capability
– Facebook Developer account with access to the Marketing API and an active Ad Account
– Google Ads account with API access (OAuth 2.0 credentials)
– n8n instance setup (cloud or self-hosted)
– Basic understanding of REST APIs and JSON

### Step 1: Set up HubSpot Webhook Trigger in n8n

1. In HubSpot, navigate to **Settings > Integrations > Webhooks** (or create a custom app if needed).
2. Create a webhook subscription for **contact property change** events, targeting properties relevant to retargeting triggers (e.g., Lifecycle Stage).
3. Set the webhook URL to point to your n8n webhook endpoint (e.g., `https://your-n8n-instance.com/webhook/hubspot-contact-update`).

In n8n:
1. Add a **Webhook** node.
2. Configure the HTTP method as **POST**.
3. Define the path to match what is set in HubSpot.
4. Save and activate the workflow (for test mode, keep it manual).

### Step 2: Parse HubSpot Contact Update Data

Add a **Set** or **Function** node after the Webhook node to extract and structure the payload data.

Example code for the Function node:
“`javascript
return [
{
json: {
contactId: $json.objectId,
properties: $json.properties
}
}
];
“`

### Step 3: Fetch Full Contact Details from HubSpot

Add an **HTTP Request** node:
– Method: GET
– URL: `https://api.hubapi.com/contacts/v1/contact/vid/{{$json[“contactId”]}}/profile?hapikey=YOUR_HUBSPOT_API_KEY`

Parse and store relevant contact properties (e.g., email, lifecycle stage).

### Step 4: Evaluate Conditions for Retargeting

Add an **IF** node to check if the contact qualifies for retargeting.

Example condition:
– `properties.lifecycle_stage` is equal to `marketingqualifiedlead`

Only contacts matching criteria proceed to the next steps.

### Step 5: Update Facebook Custom Audience

Add an **HTTP Request** node configured to interact with Facebook Marketing API:
– Endpoint: POST `https://graph.facebook.com/v14.0/{custom_audience_id}/users`
– Query Params: `access_token=YOUR_FACEBOOK_ACCESS_TOKEN`
– Body (JSON):
“`json
{
“payload”: {
“schema”: “EMAIL_SHA256”,
“data”: [““]
}
}
“`

**Notes:**
– You must hash email addresses with SHA256 before sending.
– Manage Facebook API permissions carefully.

### Step 6: Update Google Ads Customer Match List

Because Google Ads API setup is complex, here is a simplified approach:

1. Use a **Google Ads Customer Match** integration if available; otherwise, use Google Ads API with OAuth.
2. Upload emails to the user list (customer match) via the `customerUserListService`.

Add an **HTTP Request** node or custom function to upload the contact’s email to Google Ads Customer Match list.

### Step 7: Optional – Send Slack Notification

For real-time visibility, add a Slack node:
– Message example: “Contact {{email}} updated to {{lifecycle_stage}} and added to retargeting audiences.”

Configure Slack webhook URL and channel.

### Step 8: Testing Your Workflow

– Update a test contact in HubSpot to simulate property change.
– Observe that n8n receives the webhook.
– Verify conditional logic filters as expected.
– Confirm Facebook and Google Ads custom audiences updated.
– Check Slack notifications (if enabled).

### Common Errors and Troubleshooting

– **Webhook not triggering:** Check webhook URL correctness and HubSpot webhook subscription status.
– **API Authentication failures:** Verify all API keys and OAuth tokens are correct and unexpired.
– **Facebook API rate limits:** Monitor usage and implement retry or backoff strategies.
– **Email hashing mismatches:** Ensure emails are trimmed, lowercased, and SHA256 hashed properly before API calls.
– **Google Ads API complexity:** Use client libraries or managed connectors when available.

### Tips to Make Workflow More Robust

– Add retries and error handling nodes in n8n.
– Log API responses for auditing.
– Cache OAuth tokens and refresh when needed.
– Use environment variables for API keys and secrets.
– Validate email format before processing.

### Scaling and Adaptation

– Extend condition checks to handle multiple lifecycle stages or custom events.
– Integrate other ad platforms like LinkedIn Ads or Twitter Ads.
– Use data enrichment nodes to add more context to targeting.
– Schedule periodic full syncs to reconcile audiences.
– Implement throttling in case of high update frequency.

## Summary

This guide demonstrated how to automate triggering retargeting campaigns by leveraging CRM updates using n8n workflow automation. By integrating HubSpot CRM, Facebook Ads API, and Google Ads API, marketing teams can instantly react to lead status changes, ensuring timely and personalized ad delivery.

Such automation reduces manual overhead, improves campaign accuracy, and ultimately drives higher conversion rates. The workflow is extensible and scalable to incorporate additional platforms and complex conditions as your marketing operations evolve.

## Bonus Tip: Use Encrypted Storage for API Credentials

Sensitive credentials like API keys and OAuth tokens should never be hardcoded in your workflows. Use n8n’s credential management or environment variables with encrypted storage to protect your data and comply with security best practices.

This approach secures your integrations and ensures that only authorized personnel can change workflow configurations.