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

Support for custom callbacks #7

Open
troels-a opened this issue Oct 1, 2023 · 7 comments
Open

Support for custom callbacks #7

troels-a opened this issue Oct 1, 2023 · 7 comments

Comments

@troels-a
Copy link

troels-a commented Oct 1, 2023

Hello

I found myself in need of support for custom callbacks so I forked this repo and tried it out. It seems to work great:) Let me know if you want me to create a PR for this. Thanks for the work on this repo btw - great stuff.

main...troels-a:next-iubenda:main

Best,
Troels

@liarco
Copy link
Member

liarco commented Oct 3, 2023

Hi @troels-a,
thank you for your feedback! :)

I would be happy to review this as a PR, I see some small changes that we might need to make before we can merge this, but I think it might be a useful feature. 💪

@troels-a
Copy link
Author

troels-a commented Oct 3, 2023

Nice! I'll get the pr ready asap.

@cristinaITdeveloper
Copy link

When will the PR be fixed and merged? I need the callbacks too. Thanks

@liarco
Copy link
Member

liarco commented Nov 21, 2024

When will the PR be fixed and merged? I need the callbacks too. Thanks

Hi @cristinaITdeveloper, the PR is not ready yet and we still didn't find real use cases in our projects to justify working on this specific feature, but if you have any examples to share I would be happy to discuss them.

@cristinaITdeveloper
Copy link

I answered in issue #13

@m00tt
Copy link

m00tt commented Dec 18, 2024

Hi,
I also need to use custom callbacks.

I have the case of Microsoft Clarity that in early 2025 requires the configuration of cookie consent via API by setting an appropriate value.
https://learn.microsoft.com/en-us/clarity/setup-and-installation/clarity-api

I would need a way to simply set window.clarity(“consent”) when the user accepts the Iubenda policy.

Is there another way besides custom callbacks?

Thanks!

@liarco
Copy link
Member

liarco commented Dec 19, 2024

Hi @m00tt, thank you very much for sharing this use case.

I see your point, and I understand that this is something that would not work well with React components alone, as you need to trigger a side effect without rendering anything. My main concern with enabling the callbacks directly from Iubenda is adding something that might start to work inconsistently compared to the rest of the library. Maybe it would be better if I could wrap Iubenda's callbacks in a dedicated subset of callbacks that behave exactly the same as the rest of this library, so we can have the best of both approaches but with consistent behavior.

What do you think about this? Do you have any suggestions about what events would really matter?

In the meanwhile, would you mind trying this approach? This should achieve a similar results but using a component with a useEffect instead of callbacks:

'use client';

import { useEffect } from 'react';
import { useIubenda } from '@mep-agency/next-iubenda';

const ConsentAwareRunner = () => {
  // See https://github.com/mep-agency/next-iubenda/blob/8fafe8fde7f5c1f458863643e252f8a9adae5837/src/contexts/IubendaContext.tsx#L20-L49
  const { userPreferences } = useIubenda();

  useEffect(() => {
    // Do things whenever the userPreferences object changes
  }, [userPreferences]);

  // Return an empty component so this can be placed anywhere in the DOM.
  // This is kinda hacky, but serves the purpose of having a component with side effects only.
  return <></>;
};

export default ConsentAwareRunner;

@cristinaITdeveloper maybe this can help you too?

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

No branches or pull requests

4 participants