@rakutenanalytics/rat-react 0.3.1-rc.716ed0a

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.
@@ -0,0 +1,49 @@
1
+ import { ReactNode } from 'react';
2
+ import { TrackerOptions } from '@rakutenanalytics/rat-ts';
3
+ /**
4
+ * Configuration object for initializing trackers in TrackerProvider
5
+ * @public
6
+ */
7
+ export interface TrackerProviderConfig {
8
+ /** Unique key to identify the tracker */
9
+ key: string;
10
+ /** Tracker configuration options */
11
+ options: TrackerOptions;
12
+ }
13
+ /**
14
+ * Props for the TrackerProvider component
15
+ */
16
+ interface TrackerProviderProps {
17
+ /** React children components */
18
+ children: ReactNode;
19
+ /** Array of default trackers to initialize on mount */
20
+ defaultTrackers?: TrackerProviderConfig[];
21
+ }
22
+ /**
23
+ * React context provider that manages multiple Tracker instances.
24
+ * Provides access to trackers throughout the component tree via useTrackerContext hook.
25
+ *
26
+ * @example
27
+ * ```tsx
28
+ * import { TrackerProvider, ReceiverEndpoint } from '@rakutenanalytics/rat-react';
29
+ *
30
+ * const trackers = [
31
+ * { key: 'default', options: { accountId: 999, serviceId: 1 } },
32
+ * { key: 'uk', options: { accountId: 123, serviceId: 1, mainReceiver: ReceiverEndpoint.UK } }
33
+ * ];
34
+ *
35
+ * function App() {
36
+ * return (
37
+ * <TrackerProvider defaultTrackers={trackers}>
38
+ * <YourAppComponents />
39
+ * </TrackerProvider>
40
+ * );
41
+ * }
42
+ * ```
43
+ *
44
+ * @param props - The component props
45
+ * @returns Provider component that wraps children with tracker context
46
+ * @public
47
+ */
48
+ export declare const TrackerProvider: ({ children, defaultTrackers, }: TrackerProviderProps) => import("react/jsx-runtime").JSX.Element;
49
+ export {};
@@ -0,0 +1,48 @@
1
+ import { default as React } from 'react';
2
+ import { Tracker } from '@rakutenanalytics/rat-ts';
3
+ /**
4
+ * Props for the VisibilityTracker component
5
+ * @public
6
+ */
7
+ export interface VisibilityTrackerProps {
8
+ /** React children to be rendered inside the visibility tracker */
9
+ children: React.ReactNode;
10
+ /** Optional tracker instance to send visibility events */
11
+ tracker?: Tracker;
12
+ /** Unique identifier for the component, used in tracking events */
13
+ id: string;
14
+ /** Callback function called when visibility changes */
15
+ onChange?: (isVisible: boolean) => void;
16
+ /** Whether to track visibility only once (default: true) */
17
+ once?: boolean;
18
+ /** Optional CSS styles to apply to the container */
19
+ style?: React.CSSProperties;
20
+ }
21
+ /**
22
+ * A React component that tracks when it becomes visible in the viewport
23
+ * and automatically sends an "appear" event to the provided tracker.
24
+ *
25
+ * @example
26
+ * ```tsx
27
+ * import { VisibilityTracker, useTracker } from '@rakutenanalytics/rat-react';
28
+ *
29
+ * function ProductCard() {
30
+ * const tracker = useTracker({ accountId: 999, serviceId: 1 });
31
+ *
32
+ * return (
33
+ * <VisibilityTracker
34
+ * tracker={tracker}
35
+ * id="product-card-123"
36
+ * once={true}
37
+ * >
38
+ * <div>Product content here</div>
39
+ * </VisibilityTracker>
40
+ * );
41
+ * }
42
+ * ```
43
+ *
44
+ * @param props - The component props
45
+ * @returns A div element that wraps the children and tracks visibility
46
+ * @public
47
+ */
48
+ export declare const VisibilityTracker: React.FC<VisibilityTrackerProps>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The SDK source identifier for rat-react
3
+ * @internal
4
+ */
5
+ export declare const SDK_SOURCE = "rat-react";
6
+ /**
7
+ * The current version of rat-react SDK
8
+ * @internal
9
+ */
10
+ export declare const SDK_VERSION: string;
@@ -0,0 +1,10 @@
1
+ import { Tracker, TrackerOptions } from '@rakutenanalytics/rat-ts';
2
+ /**
3
+ * Creates a Tracker instance with rat-react SDK identity.
4
+ * This utility ensures all trackers created within rat-react report the correct SDK source and version.
5
+ *
6
+ * @param options - Configuration options for the tracker
7
+ * @returns A new Tracker instance configured with rat-react SDK identity
8
+ * @internal
9
+ */
10
+ export declare function createTracker(options: TrackerOptions): Tracker;
@@ -0,0 +1,9 @@
1
+ interface UseVisibilityOptions {
2
+ onChange?: (isVisible: boolean) => void;
3
+ once?: boolean;
4
+ }
5
+ declare function useVisibility(options: UseVisibilityOptions): {
6
+ isVisible: boolean;
7
+ containerRef: import('react').MutableRefObject<HTMLDivElement | null>;
8
+ };
9
+ export default useVisibility;
@@ -0,0 +1,7 @@
1
+ export { useTracker } from './useTracker';
2
+ export { useTrackerContext } from './useTrackerContext';
3
+ export { TrackerProvider } from './TrackerProvider';
4
+ export { VisibilityTracker } from './VisibilityTracker';
5
+ export type { TrackerProviderConfig } from './TrackerProvider';
6
+ export { TransportMethod, ReceiverEndpoint, AflgEnum, ChkoutEnum, IfrEnum, IsscEnum, MnetwEnum, MoriEnum, NavtypeEnum, OaEnum, PglEnum, PgtEnum, PowerstatusEnum, SrtEnum, } from '@rakutenanalytics/rat-ts';
7
+ export type { TrackerOptions, PageviewParams, ClickEventParams, InputGenericParams, } from '@rakutenanalytics/rat-ts';
@@ -0,0 +1,32 @@
1
+ import { Tracker, TrackerOptions } from '@rakutenanalytics/rat-ts';
2
+ /**
3
+ * React hook that creates and manages a Tracker instance.
4
+ * The tracker is initialized when the component mounts and recreated when accountId or serviceId changes.
5
+ *
6
+ * @example
7
+ * ```tsx
8
+ * import { useTracker } from '@rakutenanalytics/rat-react';
9
+ *
10
+ * function ProductPage() {
11
+ * const tracker = useTracker({
12
+ * accountId: 999,
13
+ * serviceId: 1
14
+ * });
15
+ *
16
+ * React.useEffect(() => {
17
+ * if (tracker) {
18
+ * tracker.sendPageviewEvent({
19
+ * params: { pageName: 'product' }
20
+ * });
21
+ * }
22
+ * }, [tracker]);
23
+ *
24
+ * return <div>Product content</div>;
25
+ * }
26
+ * ```
27
+ *
28
+ * @param options - Configuration options for the tracker
29
+ * @returns Tracker instance or null if not yet initialized
30
+ * @public
31
+ */
32
+ export declare const useTracker: (options: TrackerOptions) => Tracker | null;
@@ -0,0 +1,42 @@
1
+ import { Tracker, TrackerOptions } from '@rakutenanalytics/rat-ts';
2
+ /**
3
+ * Type definition for the tracker context
4
+ * @public
5
+ */
6
+ export interface TrackerContextType {
7
+ /** Function to retrieve a tracker by its key */
8
+ getTracker: (key: string) => Tracker | undefined;
9
+ /** Function to add a new tracker with the given key and options */
10
+ addTracker: (key: string, options: TrackerOptions) => void;
11
+ }
12
+ export declare const TrackerContext: import('react').Context<TrackerContextType | undefined>;
13
+ /**
14
+ * Hook to access the tracker context provided by TrackerProvider.
15
+ * Must be used within a TrackerProvider component.
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * import { useTrackerContext } from '@rakutenanalytics/rat-react';
20
+ *
21
+ * function MyComponent() {
22
+ * const { getTracker, addTracker } = useTrackerContext();
23
+ *
24
+ * const defaultTracker = getTracker('default');
25
+ *
26
+ * const handleClick = () => {
27
+ * if (defaultTracker) {
28
+ * defaultTracker.sendClickEvent({
29
+ * params: { itemId: ['product-123'] }
30
+ * });
31
+ * }
32
+ * };
33
+ *
34
+ * return <button onClick={handleClick}>Track Click</button>;
35
+ * }
36
+ * ```
37
+ *
38
+ * @returns The tracker context containing getTracker and addTracker functions
39
+ * @throws Error if used outside of a TrackerProvider
40
+ * @public
41
+ */
42
+ export declare const useTrackerContext: () => TrackerContextType;
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@rakutenanalytics/rat-react",
3
+ "private": false,
4
+ "version": "0.3.1-rc.716ed0a",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/lib/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/lib/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "LICENSE"
19
+ ],
20
+ "license": "MIT",
21
+ "repository": "https://github.com/rakutenanalytics/rat-react",
22
+ "publishConfig": {
23
+ "registry": "https://registry.npmjs.org",
24
+ "access": "public"
25
+ },
26
+ "peerDependencies": {
27
+ "react": ">=18.3.1 <20.0.0",
28
+ "react-dom": ">=18.3.1 <20.0.0"
29
+ },
30
+ "dependencies": {
31
+ "@rakutenanalytics/rat-ts": "^0.6.2"
32
+ }
33
+ }