Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions .github/workflows/npm-cd-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@ on:
push:
tags:
- "5.[0-9]+.[0-9]+"
permissions:
id-token: write
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v2
- uses: actions/setup-node@v4
with:
node-version: "22.x"
node-version: "24.x"
registry-url: "https://registry.npmjs.org"
- name: Enable Corepack
run: corepack enable
- name: Set Yarn Version
run: corepack prepare [email protected] --activate
- run: yarn install
- run: yarn test --coverage
- run: yarn test
- run: yarn build
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish to npm with OIDC
run: NODE_AUTH_TOKEN="" npm publish --provenance --access public
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@flagship.io/react-native-sdk",
"version": "5.0.2",
"version": "5.0.1",
"description": "Flagship SDK for React Native",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -23,7 +23,7 @@
"url": "git+https://github.com/abtasty/flagship-react-native-sdk.git"
},
"dependencies": {
"@flagship.io/react-sdk": "^5.2.1"
"@flagship.io/react-sdk": "^5.2.2"
},
"peerDependencies": {
"@react-native-async-storage/async-storage": ">=1.17.0",
Expand Down
23 changes: 14 additions & 9 deletions src/FlagshipHooks.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use client'

import { Flagship, IPageView, UseFlagshipOutput as OriginalUseFlagshipOutput, useFlagship as useFs } from '@flagship.io/react-sdk'
import { Flagship, IPageView, UseFlagshipOutput as OriginalUseFlagshipOutput, useFlagship as useFs, Visitor } from '@flagship.io/react-sdk'
import { useCallback, useMemo } from 'react';
import { Dimensions, PixelRatio, Platform } from 'react-native';
import { VisitorAugmented } from './type';

export type UseFlagshipOutput = Omit<OriginalUseFlagshipOutput, 'collectEAIEventsAsync'> & {
/**
Expand All @@ -28,6 +27,7 @@ export type UseFlagshipOutput = Omit<OriginalUseFlagshipOutput, 'collectEAIEven

type PlatformOS = typeof Platform.OS;


const DEVICE_CATEGORY_MAP: Record<PlatformOS, string> = {
ios: 'iphone',
android: 'android',
Expand All @@ -46,7 +46,7 @@ const createPageView = (
const config = Flagship.getConfig();

return {
visitorId: visitorId,
visitorId,
customerAccountId: config?.envId ?? '',
currentUrl: screenName,
hasAdBlocker: false,
Expand Down Expand Up @@ -77,20 +77,25 @@ export const useFlagship = (): UseFlagshipOutput => {
const fs = useFs()

const sendEaiPageViewAsync = useCallback(async(screenName: string): Promise<void> =>{
if (!fs.context) {
if (!fs.context || !fs.visitorId) {
return
}
const pageView :IPageView = createPageView(fs.visitorId as string, screenName)
const visitor = Flagship.getVisitor() as any
const pageView :IPageView = createPageView(fs.visitorId, screenName)
const visitor = Flagship.getVisitor() as unknown as VisitorAugmented

if (typeof visitor.sendEaiPageView !== 'function') {
return
}

visitor.sendEaiPageView(pageView)
}, [fs.context])
}, [fs.context, fs.visitorId])

const collectEAIEventsAsync = useCallback(async (screenName:string): Promise<void> => {
if (!fs.context) {
return
}
const pageView :IPageView = createPageView(fs.visitorId as string, screenName)
return (fs.collectEAIEventsAsync as any)(pageView)
return (fs.collectEAIEventsAsync as (page:IPageView)=>void)(pageView)
}, [fs.collectEAIEventsAsync, fs.context])

return useMemo(()=>({
Expand Down
11 changes: 8 additions & 3 deletions src/FlagshipProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,13 @@ const FlagshipProviderFunc = ({
const clientCache = await AsyncStorage.getItem(CLIENT_CACHE_KEY);

const augmentedFlagship = Flagship as AugmentedFlagship;
augmentedFlagship.setVisitorProfile(clientCache);
augmentedFlagship.setOnSaveVisitorProfile(saveVisitorProfile);

if (typeof augmentedFlagship.setVisitorProfile === 'function') {
augmentedFlagship.setVisitorProfile(clientCache);
}
if (typeof augmentedFlagship.setOnSaveVisitorProfile === 'function') {
augmentedFlagship.setOnSaveVisitorProfile(saveVisitorProfile);
}

firstTimeInitRef.current = !clientCache;
} catch (error) {
Expand All @@ -71,7 +76,7 @@ const FlagshipProviderFunc = ({
CONTEXT_LOAD_PREDEFINED
);
}
}, []);
}, [saveVisitorProfile]);

const updateVisitorData = useCallback(
(data: VisitorData): VisitorData => ({
Expand Down
23 changes: 21 additions & 2 deletions src/TouchCaptureProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Dimensions
} from 'react-native';
import { MAX_CLICK_PATH_LENGTH, TIMEOUT_DURATION } from './Constant';
import { VisitorAugmented } from './type';

interface TouchCaptureProviderProps {
children: React.ReactNode;
Expand All @@ -29,7 +30,7 @@ function TouchCaptureProviderFunc({ children }: TouchCaptureProviderProps) {

useEffect(() => {
const visitor = Flagship.getVisitor() as any;
if (visitor) {
if (visitor && typeof visitor.onEAICollectStatusChange === 'function') {
visitor.onEAICollectStatusChange(onEAICollectStatusChange);
}
}, [fs]);
Expand All @@ -49,7 +50,14 @@ function TouchCaptureProviderFunc({ children }: TouchCaptureProviderProps) {
screenSize: `${screen.width},${screen.height};`
};

(visitor as any).sendEaiVisitorEvent(visitorEvent);
if (
typeof (visitor as unknown as VisitorAugmented)
.sendEaiVisitorEvent === 'function'
) {
(visitor as unknown as VisitorAugmented).sendEaiVisitorEvent(
visitorEvent
);
}
},
[]
);
Expand Down Expand Up @@ -130,6 +138,17 @@ function TouchCaptureProviderFunc({ children }: TouchCaptureProviderProps) {
[processTouchMoveEvent]
);

useEffect(() => {
return () => {
if (touchPathTimeoutId.current) {
clearTimeout(touchPathTimeoutId.current);
}
if (touchPositionTimeoutId.current) {
clearTimeout(touchPositionTimeoutId.current);
}
};
}, []);

return (
<View
style={styles.container}
Expand Down
6 changes: 6 additions & 0 deletions src/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { IPageView, IVisitorEvent, Visitor } from "@flagship.io/react-sdk";

export type VisitorAugmented = typeof Visitor & {
sendEaiPageView: (pageView: IPageView) => void;
sendEaiVisitorEvent: (visitorEvent: IVisitorEvent) => void;
}
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ __metadata:
"@babel/preset-env": "npm:^7.14.7"
"@babel/preset-react": "npm:^7.14.5"
"@babel/preset-typescript": "npm:^7.14.5"
"@flagship.io/react-sdk": "npm:^5.2.1"
"@flagship.io/react-sdk": "npm:^5.2.2"
"@react-native-async-storage/async-storage": "npm:^1.17.11"
"@react-native-community/eslint-config": "npm:^1.1.0"
"@testing-library/jest-native": "npm:^3.1.0"
Expand Down Expand Up @@ -1695,15 +1695,15 @@ __metadata:
languageName: unknown
linkType: soft

"@flagship.io/react-sdk@npm:^5.2.1":
version: 5.2.1
resolution: "@flagship.io/react-sdk@npm:5.2.1"
"@flagship.io/react-sdk@npm:^5.2.2":
version: 5.2.2
resolution: "@flagship.io/react-sdk@npm:5.2.2"
dependencies:
"@flagship.io/js-sdk": "npm:^5.1.7"
encoding: "npm:^0.1.13"
peerDependencies:
react: ">=16.8.0"
checksum: 10c0/e09d3927dd55a65289e1b51b14c179f8758e885a69f5199539930f02ba91ade5b35e70830fb889d39e7e36cbcb1aa1a5d83d8321827a2d1cade7b210e2297ca3
checksum: 10c0/5756018456ccbb30436d7647310b894cda5f4ffbf9fb7efd0fa5b5871876e6c809d23ea2c759818c457559dc4d79b332a0b8c7da342821ed118712551f0ab3b7
languageName: node
linkType: hard

Expand Down