@easyfunnel/react 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
2
3
  import { ReactNode } from 'react';
3
4
  import { EasyFunnelOptions, EasyFunnelConfig, Tracker } from '@easyfunnel/sdk';
4
5
 
@@ -11,5 +12,6 @@ declare function useEasyFunnel(): Tracker | null;
11
12
 
12
13
  declare function useTrack(): (eventName: string, properties?: Record<string, any>) => void;
13
14
  declare function useIdentify(): (userId: string) => void;
15
+ declare function useSectionRef<T extends HTMLElement = HTMLElement>(sectionName: string): react.RefObject<T | null>;
14
16
 
15
- export { EasyFunnelProvider, useEasyFunnel, useIdentify, useTrack };
17
+ export { EasyFunnelProvider, useEasyFunnel, useIdentify, useSectionRef, useTrack };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
2
3
  import { ReactNode } from 'react';
3
4
  import { EasyFunnelOptions, EasyFunnelConfig, Tracker } from '@easyfunnel/sdk';
4
5
 
@@ -11,5 +12,6 @@ declare function useEasyFunnel(): Tracker | null;
11
12
 
12
13
  declare function useTrack(): (eventName: string, properties?: Record<string, any>) => void;
13
14
  declare function useIdentify(): (userId: string) => void;
15
+ declare function useSectionRef<T extends HTMLElement = HTMLElement>(sectionName: string): react.RefObject<T | null>;
14
16
 
15
- export { EasyFunnelProvider, useEasyFunnel, useIdentify, useTrack };
17
+ export { EasyFunnelProvider, useEasyFunnel, useIdentify, useSectionRef, useTrack };
package/dist/index.js CHANGED
@@ -52,6 +52,7 @@ __export(index_exports, {
52
52
  EasyFunnelProvider: () => EasyFunnelProvider,
53
53
  useEasyFunnel: () => useEasyFunnel,
54
54
  useIdentify: () => useIdentify,
55
+ useSectionRef: () => useSectionRef,
55
56
  useTrack: () => useTrack
56
57
  });
57
58
  module.exports = __toCommonJS(index_exports);
@@ -129,10 +130,26 @@ function useIdentify() {
129
130
  [tracker]
130
131
  );
131
132
  }
133
+ function useSectionRef(sectionName) {
134
+ const ref = (0, import_react2.useRef)(null);
135
+ (0, import_react2.useEffect)(() => {
136
+ const el = ref.current;
137
+ if (el) {
138
+ el.setAttribute("data-ef-section", sectionName);
139
+ }
140
+ return () => {
141
+ if (el) {
142
+ el.removeAttribute("data-ef-section");
143
+ }
144
+ };
145
+ }, [sectionName]);
146
+ return ref;
147
+ }
132
148
  // Annotate the CommonJS export names for ESM import in node:
133
149
  0 && (module.exports = {
134
150
  EasyFunnelProvider,
135
151
  useEasyFunnel,
136
152
  useIdentify,
153
+ useSectionRef,
137
154
  useTrack
138
155
  });
package/dist/index.mjs CHANGED
@@ -75,7 +75,7 @@ function useEasyFunnel() {
75
75
  }
76
76
 
77
77
  // src/hooks.ts
78
- import { useCallback } from "react";
78
+ import { useCallback, useEffect as useEffect2, useRef as useRef2 } from "react";
79
79
  function useTrack() {
80
80
  const tracker = useEasyFunnel();
81
81
  return useCallback(
@@ -108,9 +108,25 @@ function useIdentify() {
108
108
  [tracker]
109
109
  );
110
110
  }
111
+ function useSectionRef(sectionName) {
112
+ const ref = useRef2(null);
113
+ useEffect2(() => {
114
+ const el = ref.current;
115
+ if (el) {
116
+ el.setAttribute("data-ef-section", sectionName);
117
+ }
118
+ return () => {
119
+ if (el) {
120
+ el.removeAttribute("data-ef-section");
121
+ }
122
+ };
123
+ }, [sectionName]);
124
+ return ref;
125
+ }
111
126
  export {
112
127
  EasyFunnelProvider,
113
128
  useEasyFunnel,
114
129
  useIdentify,
130
+ useSectionRef,
115
131
  useTrack
116
132
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyfunnel/react",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "React/Next.js provider for easyfunnel.co analytics",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -13,7 +13,7 @@
13
13
  "dev": "tsup src/index.ts --format cjs,esm --dts --external react --watch"
14
14
  },
15
15
  "dependencies": {
16
- "@easyfunnel/sdk": "^0.1.2"
16
+ "@easyfunnel/sdk": "^0.1.4"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "next": ">=14.0.0",