# Hubspot chat in Nextjs

**URL:** <https://community.hubspot.com/t/hubspot-chat-in-nextjs/119367>\
**Category:** APIs & Integrations\
**Tags:** free, timeline-and-extensions-apis\
**Created:** [October 28, 2024, 9:41pm UTC](https://community.hubspot.com/t/hubspot-chat-in-nextjs/119367 "2024-10-28T21:41:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lpansarini](https://avatars.discourse-cdn.com/v4/letter/l/838e76/32.png) [@lpansarini](https://community.hubspot.com/u/lpansarini)\
**Post date:** [October 28, 2024, 9:41pm UTC](https://community.hubspot.com/t/hubspot-chat-in-nextjs/119367/1 "2024-10-28T21:41:51Z")

</div>

I have been trying to use Hubspot chat in company website ([https://machinerypartner.com/](https://machinerypartner.com/)) and we tried many times, but seems Hubspot cannot work on Nextjs 14. I tried many ways like the others posts in forum, but without success  
I created that hubspot tracker also to try those connections, and seems not working neither

‘use client’;

import { useEffect, useRef } from ‘react’;

import { usePathname, useSearchParams } from ‘next/navigation’;

const HubspotTracker = () =\> {

const pathname = usePathname()

const searchParams = useSearchParams()

const searchParamsDict = Object.fromEntries(searchParams ? searchParams.entries() : [])

var firstLoad = useRef(true);

useEffect(() =\> {

if (typeof window !== ‘undefined’) {

var \_hsq = (window.\_hsq = window.\_hsq || []);

window.hsConversationsSettings = {

loadImmediately: true,

inlineEmbedSelector: “#my-chat-container”,

enableWidgetCookieBanner: true,

disableAttachment: true,

};

if (firstLoad.current === true) {

\_hsq.push([‘setPath’, pathname]);

\_hsq.push([‘trackPageView’]);

// I think we only need the trackPageView entry once before the identify.

\_hsq.push([‘setPath’, pathname]);

\_hsq.push([‘trackPageView’]);

window.HubSpotConversations?.widget?.load()

window.HubSpotConversations?.widget?.refresh()

firstLoad.current = false;

} else {

\_hsq.push([‘setPath’, pathname]);

\_hsq.push([‘trackPageView’]);

window.HubSpotConversations?.widget?.load()

window.HubSpotConversations?.widget?.refresh()

}

}

}, [pathname, searchParamsDict]);

return null;

};

export default HubspotTracker;  
My script:

\<Script

src=“[https://js.hs-scripts.com/MY\_CODE\_HERE.js](https://js.hs-scripts.com/MY_CODE_HERE.js)”

strategy=“beforeInteractive”

id=“hs-script-loader”

async

defer

/\>

Can u guys provide some help?

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [October 29, 2024, 8:02pm UTC](https://community.hubspot.com/t/hubspot-chat-in-nextjs/119367/2 "2024-10-29T20:02:03Z")

</div>

Hi, @lpansarini 👋 I agree with your findings, finding support for NextJS in the community is challenging. I did find a few community members who’ve helped with these types of questions in the past, and I’d like to invite them to the converstaion — hey @Kevin-C @Teun @tverdokhlib1 do you have any suggestions on next steps or perhaps another way to approach this challenge?

Thank you very much for taking a look! — Jaycee
