Skip to content

Commit

Permalink
feat(react-tracking): synchronous trackers
Browse files Browse the repository at this point in the history
  • Loading branch information
thijsdaniels committed Mar 27, 2024
1 parent 8b7c41c commit 79d65a4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/tricky-mirrors-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@codedazur/react-tracking": minor
---

Trackers can now be synchronous as wel as asynchronous.
4 changes: 3 additions & 1 deletion packages/react-tracking/components/TrackingProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export interface TrackingProviderProps {
children?: ReactNode;
}

export type Tracker = (event: BaseEvent & EventMetadata) => Promise<void>;
export type Tracker = (
event: BaseEvent & EventMetadata,
) => void | Promise<void>;

export function TrackingProvider({
slug,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-tracking/utilities/createConsoleTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Tracker } from "../components/TrackingProvider";
export function createConsoleTracker({
method = "dir",
}: { method?: "log" | "info" | "dir" } = {}): Tracker {
return async function logTracker(event) {
return function logTracker(event) {
console[method](event);
};
}
2 changes: 1 addition & 1 deletion packages/react-tracking/utilities/createGtmTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ declare global {
export function createGtmTracker({
prefix,
}: { prefix?: string } = {}): Tracker {
return async function gtmTracker({ type, ...event }) {
return function gtmTracker({ type, ...event }) {
window.dataLayer.push({
event: [prefix, type].filter(Boolean).join("."),
...event,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export async function createStorybookTracker({
}: { name?: string } = {}): Promise<Tracker> {
const { action } = await import("@storybook/addon-actions");

return async function storybookTracker(event) {
return function storybookTracker(event) {
action(name)(event);
};
}

0 comments on commit 79d65a4

Please sign in to comment.