GDPRChecker

Home / Knowledge Base / HubSpot Tracking Next.js Cookie Consent: A Practical Compliance Guide

Website Compliance

HubSpot Tracking Next.js Cookie Consent: A Practical Compliance Guide

A practical guide for Next.js developers on implementing HubSpot Tracking with GDPR-compliant cookie consent. Covers requirements, step-by-step implementation, common mistakes, and validation using GDPRChecker. Includes a checklist and FAQ to help close consent gaps.

Run a free GDPR compliance scanPreview the findings before choosing a CMP.

Author

GDPRChecker Editorial Team

Reviewed by

Privacy & Compliance Research Team

Last updated

July 2026

Reading time

9 min read

Educational guidance for compliance readiness — not legal advice. Requirements vary by jurisdiction and your specific processing activities.

Introduction

Updated for 2026 compliance practices.

Understanding HubSpot Tracking Next.js cookie consent is essential for website owners who want to balance marketing insights with privacy compliance. When you embed HubSpot’s tracking code in a Next.js application, you’re likely collecting personal data—such as IP addresses, page views, and form interactions—that falls under the GDPR if your visitors are in the EU. This guide walks you through what this integration means for compliance, how to implement consent correctly, and how to validate your setup with tools like GDPRChecker. We’ll cover technical steps, common pitfalls, and a practical checklist to help you close the gaps in your consent implementation.

GDPR Requirements and Compliance Expectations

When implementing HubSpot Tracking in Next.js, you must meet several GDPR requirements. First, consent must be freely given, specific, informed, and unambiguous. This means your cookie banner cannot have pre-ticked boxes, and the user must take a clear affirmative action. You also need to provide detailed information about what data HubSpot collects, why, and how it’s used—typically in your privacy policy.

Second, you must respect the principle of data minimization. Only load HubSpot tracking if the user has consented to the relevant category (e.g., “Analytics” or “Marketing”). If you use HubSpot for multiple purposes (e.g., analytics and personalization), you may need separate consent options. The GDPR.eu overview (GDPR.eu) emphasizes that bundling consents is not allowed unless they are for the same purpose.

Third, you must be able to demonstrate compliance. This means keeping records of consent, including timestamps and the consent scope. HubSpot itself can store consent status if you use its forms and API, but for tracking cookies, you’ll need a CMP that logs consent and integrates with your Next.js frontend.

Fourth, consider the ePrivacy Directive (Cookie Law) alongside GDPR. It requires consent for storing or accessing information on a user’s device, which covers HubSpot cookies. The only exception is strictly necessary cookies, but HubSpot’s tracking cookies are not strictly necessary for the website to function.

Finally, if you use Google services alongside HubSpot, you may need to implement Google Consent Mode. This allows tags to adjust their behavior based on consent state. While HubSpot doesn’t natively support Consent Mode, you can still manage it through your CMP and custom code. For more on Consent Mode, see our guide on Google Consent Mode v2.

Step-by-Step Implementation for Next.js

Implementing HubSpot Tracking with cookie consent in Next.js requires careful orchestration. Here’s a practical approach:

1. Choose a Consent Management Platform (CMP)

Select a CMP that provides a JavaScript API to check consent status. Popular options include Cookiebot, OneTrust, or a custom solution. The CMP should allow you to define a consent category for “Marketing” or “Analytics” and expose a function like hasConsented('marketing').

2. Set Up the Consent Banner

Integrate the CMP’s banner script in your Next.js _document.js or _app.js. Ensure it loads early and blocks all tracking scripts by default. The banner must not set HubSpot cookies before consent. Configure the banner to fire a callback when consent changes.

3. Conditionally Load HubSpot Script

In your Next.js app, create a custom hook or component that checks consent before injecting the HubSpot tracking code. For example:

// hooks/useHubSpotTracking.js
import { useEffect } from 'react';

const useHubSpotTracking = (consentGiven) => {
  useEffect(() => {
    if (consentGiven && !window.hsConversationsOnReady) {
      const script = document.createElement('script');
      script.src = '//js.hs-scripts.com/YOUR_HUBSPOT_ID.js';
      script.id = 'hs-script-loader';
      script.async = true;
      script.defer = true;
      document.body.appendChild(script);
    }
  }, [consentGiven]);
};

Then, in your main app component, call this hook only when the user has consented to the appropriate category.

4. Handle Consent Changes

Users must be able to change their consent preferences. When they do, your CMP should trigger an event. Listen for this event and either load or remove the HubSpot script accordingly. Removing the script may not delete already-set cookies, so you should also clear HubSpot cookies if consent is withdrawn. Use document.cookie to expire them.

5. Integrate with Next.js Script Component

Next.js provides a <Script> component with a strategy prop. You can use strategy="afterInteractive" but only after consent is verified. A better approach is to use dangerouslySetInnerHTML or dynamic imports to inject the script only when needed.

6. Test Server-Side Rendering (SSR) Behavior

Ensure that the HubSpot script never executes during SSR. Since consent is a client-side concept, you must guard all tracking code with typeof window !== 'undefined' checks. If you use Next.js middleware, you can also set a cookie that indicates consent, but this is complex and may not align with real-time consent changes.

7. Document and Log Consent

Use your CMP’s logging features or implement a simple logger that sends consent events to your backend. This helps demonstrate compliance if regulators ask.

For a deeper dive into consent management, read our article on Do I Need a CMP If I Do Not Run Google Ads?.

Common Mistakes and How to Avoid Them

Many Next.js developers make avoidable errors when integrating HubSpot Tracking with consent. Here are the most frequent ones:

Mistake 1: Loading HubSpot before consent. This is the cardinal sin. Even if you have a banner, if the script fires on page load, you’re non-compliant. Always defer script injection until after explicit consent.

Mistake 2: Ignoring the “Reject” flow. Some implementations only handle “Accept All” but fail to respect “Reject All” or granular preferences. Ensure that if a user rejects marketing cookies, the HubSpot script is never loaded, and no HubSpot cookies are set.

Mistake 3: Not clearing cookies on consent withdrawal. If a user changes their mind, you must stop further tracking and delete existing HubSpot cookies. Otherwise, you’re still processing data without a legal basis.

Mistake 4: Using HubSpot’s built-in consent features incorrectly. HubSpot offers a consent API for forms and emails, but it doesn’t automatically control the tracking script. You must still manage the script loading yourself.

Mistake 5: Assuming server-side consent is sufficient. Some developers try to set a consent cookie via an API route and then conditionally render the script on the server. This can break with caching and doesn’t reflect real-time consent changes. Client-side consent management is more reliable.

Mistake 6: Overlooking third-party dependencies. If you use HubSpot’s chat widget or other tools, they also set cookies and must be consent-controlled.

Mistake 7: Not testing with a scanner. Manual testing can miss pre-consent network requests. Use a tool like GDPRChecker to scan your site and verify that no HubSpot requests fire before consent.

How to Validate with GDPRChecker

After implementing consent for HubSpot Tracking in Next.js, you need to verify that it works correctly. GDPRChecker scans help verify pre-consent network requests, banner behavior, and disclosure gaps after changes. Here’s how to use it:

  1. Run a pre-consent scan. Before accepting any cookies, run a scan on your Next.js site. GDPRChecker will list all network requests and cookies set. Confirm that no HubSpot-related requests (e.g., to track.hubspot.com or js.hs-scripts.com) appear, and no HubSpot cookies are present.
  1. Test the accept flow. Accept all cookies in your banner, then rescan. Now you should see HubSpot scripts loaded and cookies set. Verify that the consent timestamp is logged.
  1. Test the reject flow. Reject all cookies and rescan. Ensure no HubSpot activity occurs. Then, change preferences to accept only necessary cookies—HubSpot should still be blocked.
  1. Check for disclosure gaps. GDPRChecker can also check if your privacy policy mentions HubSpot and the purpose of tracking. It may flag missing disclosures.
  1. Schedule regular scans. After any code or configuration change, rescan to catch regressions. This is especially important when updating Next.js or HubSpot settings.

For more on scanning, see our Google Consent Mode v2 Checker guide, which covers similar validation principles.

Implementation Checklist

Use this checklist to ensure your HubSpot Tracking Next.js cookie consent implementation is complete:

  1. To do: A CMP is integrated and displays a cookie banner before any tracking scripts load.
  2. To do: The banner provides clear information about HubSpot cookies and their purposes.
  3. To do: Consent is granular: users can opt in/out of marketing/analytics separately if needed.
  4. To do: The HubSpot tracking script is not loaded in the initial HTML or executed before consent.
  5. To do: A custom hook or component conditionally injects the HubSpot script only after consent.
  6. To do: On consent withdrawal, the HubSpot script is removed and all HubSpot cookies are cleared.
  7. To do: The implementation works with Next.js SSR and static generation without leaking tracking.
  8. To do: Consent changes are logged with timestamps for compliance records.
  9. To do: The privacy policy is updated to include HubSpot as a data processor.
  10. To do: A GDPRChecker scan confirms no pre-consent HubSpot network requests or cookies.
  11. To do: The reject flow is tested and verified to block all HubSpot tracking.
  12. To do: Regular scans are scheduled to maintain compliance after updates.

FAQ

What is HubSpot Tracking Next.js cookie consent?

It’s the practice of obtaining user permission before loading HubSpot’s tracking scripts and setting cookies in a Next.js application. This ensures compliance with GDPR and ePrivacy Directive by preventing unauthorized data collection.

Do I need HubSpot Tracking Next.js cookie consent for GDPR?

Yes, if you have EU visitors and HubSpot sets non-essential cookies or processes personal data. Consent is required unless you have another lawful basis, but for marketing and analytics, consent is the standard approach.

How do I implement HubSpot Tracking Next.js cookie consent?

Integrate a CMP, conditionally load the HubSpot script based on consent, handle consent changes, and clear cookies on withdrawal. Use client-side checks to avoid pre-consent tracking.

How can I verify HubSpot Tracking Next.js cookie consent with a scanner?

Use GDPRChecker to scan your site before and after consent. It detects pre-consent network requests, cookies, and disclosure issues, helping you confirm that HubSpot only loads after opt-in.

What are common HubSpot Tracking Next.js cookie consent mistakes?

Loading the script before consent, not handling the reject flow, failing to clear cookies on withdrawal, and assuming server-side consent is enough. Regular scanning helps catch these errors.

Next Steps for Compliance

Implementing HubSpot Tracking Next.js cookie consent is a critical step in aligning your Next.js site with GDPR. By following the steps above, you can avoid common pitfalls and ensure that your marketing data collection respects user privacy. Remember, compliance is not a one-time task—it requires ongoing monitoring and updates as regulations and technologies evolve.

To close the remaining gaps in your consent setup, run a scan with GDPRChecker today. Our tool helps you verify pre-consent network requests, banner behavior, and disclosure gaps after changes. For related guidance, explore our articles on Google Analytics GDPR Compliance, Cookie Banner Requirements, and Consent Mode v2 vs Google Certified CMP. Stay proactive and keep your website compliant.

Next step

Run a GDPRChecker scan to validate consent behavior, trackers, and disclosures after you implement the checklist above.

This guide is technical implementation guidance for website owners. It is not legal advice.

GDPRChecker guides are educational resources and do not constitute legal advice. Use them to understand technical and operational privacy requirements, and consult qualified counsel for legal interpretation.

Check Your Website in Under 60 Seconds

  • Sign in required
  • GDPR-focused checks
  • Cookie banner detection
  • Privacy policy verification