Skip to content

feat: add useTracking hook#61

Open
barinali wants to merge 1 commit intomainfrom
introduce-tracking
Open

feat: add useTracking hook#61
barinali wants to merge 1 commit intomainfrom
introduce-tracking

Conversation

@barinali
Copy link
Contributor

Proposed Changes

This pull request aims to introduce a new React hook named useTracking that returns a function to fire tracking event. As the tracking is optional, the returned function may be no-op.

A short snippet of usage:

function YetAnotherReactComponent() {
  const track = useTracking();

  React.useEffect(function viewEvent() {
    track('view');
  }, []);
}

Checklist

Ensure you provide everything we need to review your contribution:

  • Contribution meets our definition of done
  • Pull request establishes context
    • Link to related issue(s), i.e. Closes {LINK_TO_ISSUE} or Related to {LINK_TO_ISSUE}
    • Brief textual description of the changes
    • Screenshots or short videos showing UI/UX changes
    • Steps to try out, i.e. using the @bpmn-io/sr tool

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces an internal useTracking React hook intended to integrate with an (optional) bpmn-js-tracking service, along with tests and dependency metadata updates.

Changes:

  • Add optional peer dependency bpmn-js-tracking (with peerDependenciesMeta.optional).
  • Add lib/hooks/useTracking.js hook that namespaces events and no-ops when tracking is unavailable.
  • Add unit tests for the hook and update the changelog.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
package.json Adds bpmn-js-tracking as an optional peer dependency.
package-lock.json Mirrors the optional peer dependency metadata in the lockfile.
lib/hooks/useTracking.js Implements the new useTracking hook (currently not exported from the build entry).
lib/hooks/test/useTracking.spec.jsx Adds tests covering namespacing and no-op behavior.
CHANGELOG.md Documents the addition in the Unreleased section.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +7 to +14
export default function useTracking() {
const bpmnJSTracking = useService('bpmnJSTracking', false);

return useCallback((name, data) => {
if (bpmnJSTracking) {
bpmnJSTracking.track({ name: `${NAMESPACE}:${name}`, data });
}
}, [ bpmnJSTracking ]);
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

useTracking is added under lib/hooks, but the package only publishes dist (see package.json#files) and the build entry is lib/index.jsx. As-is, this hook won't be included in the built artifact or be importable by consumers. Please export it from the public entry (e.g. add a named export from lib/index.jsx and ensure it is emitted in dist), or otherwise wire it into the entry/component so it’s part of the build output.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs review Review pending

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants