Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage of Partytown #15

Open
martinbianchi opened this issue Jun 27, 2022 · 7 comments
Open

Usage of Partytown #15

martinbianchi opened this issue Jun 27, 2022 · 7 comments

Comments

@martinbianchi
Copy link

martinbianchi commented Jun 27, 2022

Hi Folks,

Not sure if here is the correct place for this.

I've been trying to implement partytown to load the hotjar script inside a worker thread instead of on the main thread but I couldn't make it work. The installation verification on Hotjar says that everything is correctly but I can't see any metric being logged.

Is it possible to make it work Hotjar with Partytown?

Here are the configs that I tried without success:

partytown = {
                lib: "/_next/static/~partytown/",
                forward: ['hj', 'hjBootstrap', 'hjLazyModules', 'hjSiteSettings', '_hjSettings'],
                resolveUrl: function (url) {
                  if (url.hostname === 'vars.hotjar.com') {
                    return new URL('my-reverse-proxy' + url.pathname + url.search);
                  }
                  return url;
                },
};
partytown = {
                lib: "/_next/static/~partytown/",
                forward: ['hj'],
                resolveUrl: function (url) {
                  if (url.hostname === 'vars.hotjar.com') {
                    return new URL('my-reverse-proxy' + url.pathname + url.search);
                  }
                  return url;
                },
};

Thanks in advance!

@tcetin
Copy link

tcetin commented Sep 18, 2023

@martinbianchi Did you find any solution to that?

@martinbianchi
Copy link
Author

@tcetin Nop :( At the time I tried, hotjar was consuming things from the main thread internally (I think it was GA). When I moved to the service worker many of those internal calls started to fail.

@tcetin
Copy link

tcetin commented Sep 18, 2023

@martinbianchi Thank you for your response. I am also trying to make it work but It seems it doesn't work in a web worker since it needs to access cookies and write cookies. I hope partytown team can find a solution for it. I also created a discussion on partytown repository: https://github.com/BuilderIO/partytown/discussions/466

@callum-gander
Copy link

callum-gander commented Nov 20, 2023

Any updates on this? We're looking to potentially use Hotjar with PartyTown at my company but can't really get started until we know it'll actually work

@Andyradall
Copy link

Following

@callum-gander
Copy link

Bumping this again

@Andyradall
Copy link

@callum-gander I do this as an alternative, simply loading Hotjar after user interaction (avoiding google pagespeed performance hit by Hotjar initiation):

import Hotjar from '@hotjar/browser';

onMount(() => {
	// Function to initialize Hotjar after user interaction
	const initHotjar = () => {
		const siteId = [your hotjar id];
		const hotjarVersion = 6;

		try {
			Hotjar.init(siteId, hotjarVersion);
		} catch (error) {
			console.error('Failed to initialize Hotjar:', error);
		}

		// Remove the event listeners after Hotjar has been initialized
		window.removeEventListener('click', initHotjar);
		window.removeEventListener('scroll', initHotjar);
	};

	// Add event listeners for the click and scroll events
	window.addEventListener('click', initHotjar);
	window.addEventListener('scroll', initHotjar);
}); 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants