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

Edgee 406 react sdk export edgee sdk methods #7

Merged
merged 6 commits into from
Feb 6, 2025

Conversation

Jer1605
Copy link
Contributor

@Jer1605 Jer1605 commented Feb 5, 2025

Export Edgee SDK Methods in React SDK

Description

This PR improves the Edgee React SDK by exporting the core Edgee tracking methods (track, user, page, consent) directly. This enhancement allows developers to use the SDK methods without accessing window.edgee manually, improving DX (Developer Experience), performance with the hook, and ensuring a cleaner integration, with a strong typing.

Changes

  • Directly export track, user, page and consent from the SDK, reducing direct interactions with the global window.edgee object.
  • Improved TypeScript definitions for stricter validation and autocompletion.
  • Ensured compatibility with dynamically loaded SDK instances with a queue - tracking calls are only made when the SDK is ready, avoiding redundant checks and improving runtime efficiency.
  • Introduced useEdgeeDataCollection() hook for optimized tracking - The hook memoizes the tracking functions with useCallback(), ensuring that they do not get recreated on every render.

Why This Change?

This enhancement simplifies the usage of Edgee in React applications by making track, user, page, and consent exports, reducing boilerplate and improving reliability.

Usage Example

import { useEdgeeDataCollection } from 'react-edgee';

const MyButton = () => {
  const { track } = useEdgeeDataCollection();
  return <button onClick={() => track({ name: 'button_click' })}>Click Me</button>;
};

export default MyButton;

Copy link
Contributor

@alexcasalboni alexcasalboni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍 I would suggest also updating the README with the new hook usage

package.json Outdated Show resolved Hide resolved
src/lib/data-collection/data-collection.hook.ts Outdated Show resolved Hide resolved
src/lib/data-collection/data-collection.hook.ts Outdated Show resolved Hide resolved
@Jer1605
Copy link
Contributor Author

Jer1605 commented Feb 6, 2025

hey @alexcasalboni , could you do a double check, I added an export of the consent method also, and included your suggestions ;) I also updated the Readme file 👍

@alexcasalboni
Copy link
Contributor

We should update the documentation here too (once merged): https://www.edgee.cloud/docs/getting-started/react-sdk

@Jer1605 Jer1605 merged commit 8338e1f into main Feb 6, 2025
4 checks passed
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

Successfully merging this pull request may close these issues.

2 participants