Skip to content

Commit

Permalink
Update NamiCampaignManager.launch
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-sumi-k committed Jun 21, 2024
1 parent 4637061 commit 27d05f6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 188 deletions.
40 changes: 4 additions & 36 deletions examples/Basic/containers/CampaignScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
NamiPaywallManager,
NamiPaywallAction,
NamiCampaignRuleType,
NamiPaywallEvent,
} from 'react-native-nami-sdk';
import {
FlatList,
Expand Down Expand Up @@ -165,43 +166,10 @@ const CampaignScreen: FC<CampaignScreenProps> = ({ navigation }) => {
console.log('error', error);

checkIfPaywallOpen();

},
(
action,
campaignId,
paywallId,
campaignName,
campaignType,
campaignLabel,
campaignUrl,
paywallName,
segmentId,
externalSegmentId,
deeplinkUrl,
skuId,
componentChangeId,
componentChangeName,
purchaseError,
purchases,
) => {
console.log('action', action);
setAction(action);
console.log('campaignId', campaignId);
console.log('paywallId', paywallId);
console.log('campaignName', campaignName);
console.log('campaignType', campaignType);
console.log('campaignLabel', campaignLabel);
console.log('campaignUrl', campaignUrl);
console.log('paywallName', paywallName);
console.log('segmentId', segmentId);
console.log('externalSegmentId', externalSegmentId);
console.log('deeplinkUrl', deeplinkUrl);
console.log('skuId', skuId);
console.log('componentChangeId', componentChangeId);
console.log('componentChangeName', componentChangeName);
console.log('purchaseError', purchaseError);
console.log('purchases', purchases);
(event: NamiPaywallEvent) => {
console.log('event', event);
setAction(event.action);
},
);
};
Expand Down
34 changes: 3 additions & 31 deletions examples/Basic/services/deeplinking.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NamiCampaignManager } from 'react-native-nami-sdk';
import { NamiCampaignManager, NamiPaywallEvent } from 'react-native-nami-sdk';

interface HandleDeepLinkParams {
url: string;
Expand All @@ -22,36 +22,8 @@ export async function handleDeepLink(params: HandleDeepLinkParams) {
(success, error) => {
console.log(success, error);
},
(
action,
campaignId,
paywallId,
campaignLabel,
campaignName,
campaignType,
campaignUrl,
segmentId,
externalSegmentId,
paywallName,
deeplinkUrl,
skuId,
purchaseError,
purchases,
) => {
console.log('action', action);
console.log('campaignId', campaignId);
console.log('paywallId', paywallId);
console.log('campaignLabel', campaignLabel);
console.log('campaignName', campaignName);
console.log('campaignType', campaignType);
console.log('campaignUrl', campaignUrl);
console.log('paywallName', paywallName);
console.log('segmentId', segmentId);
console.log('externalSegmentId', externalSegmentId);
console.log('deeplinkUrl', deeplinkUrl);
console.log('skuId', skuId);
console.log('purchaseError', purchaseError);
console.log('purchases', purchases);
(event: NamiPaywallEvent) => {
console.log('event', event);
},
);
}
Expand Down
34 changes: 3 additions & 31 deletions examples/TestNamiTV/containers/CampaignScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
Text,
TouchableOpacity,
} from 'react-native';
import { NamiCampaignManager, NamiCampaign, NamiCampaignRuleType } from 'react-native-nami-sdk';
import { NamiCampaignManager, NamiCampaign, NamiCampaignRuleType, NamiPaywallEvent } from 'react-native-nami-sdk';
import { ViewerTabProps } from '../App';
import theme from '../theme';
import { SafeAreaView } from 'react-native-safe-area-context';
Expand Down Expand Up @@ -65,36 +65,8 @@ const CampaignScreen: FC<CampaignScreenProps> = ({ navigation }) => {
console.log('successAction', successAction);
console.log('error', error);
},
(
action,
campaignId,
paywallId,
campaignName,
campaignType,
campaignLabel,
campaignUrl,
paywallName,
segmentId,
externalSegmentId,
deeplinkUrl,
skuId,
purchaseError,
purchases,
) => {
console.log('action', action);
console.log('campaignId', campaignId);
console.log('paywallId', paywallId);
console.log('campaignLabel', campaignLabel);
console.log('campaignName', campaignName);
console.log('campaignType', campaignType);
console.log('campaignUrl', campaignUrl);
console.log('paywallName', paywallName);
console.log('segmentId', segmentId);
console.log('externalSegmentId', externalSegmentId);
console.log('deeplinkUrl', deeplinkUrl);
console.log('skuId', skuId);
console.log('purchaseError', purchaseError);
console.log('purchases', purchases);
(event: NamiPaywallEvent) => {
console.log('event', event);
},
);
};
Expand Down
34 changes: 3 additions & 31 deletions examples/TestNamiTV/services/deeplinking.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NamiCampaignManager } from 'react-native-nami-sdk';
import { NamiCampaignManager, NamiPaywallEvent } from 'react-native-nami-sdk';

interface HandleDeepLinkParams {
url: string;
Expand All @@ -22,36 +22,8 @@ export async function handleDeepLink(params: HandleDeepLinkParams) {
(success, error) => {
console.log(success, error);
},
(
action,
campaignId,
paywallId,
campaignLabel,
campaignName,
campaignType,
campaignUrl,
segmentId,
externalSegmentId,
paywallName,
deeplinkUrl,
skuId,
purchaseError,
purchases,
) => {
console.log('action', action);
console.log('campaignId', campaignId);
console.log('paywallId', paywallId);
console.log('campaignLabel', campaignLabel);
console.log('campaignName', campaignName);
console.log('campaignType', campaignType);
console.log('campaignUrl', campaignUrl);
console.log('paywallName', paywallName);
console.log('segmentId', segmentId);
console.log('externalSegmentId', externalSegmentId);
console.log('deeplinkUrl', deeplinkUrl);
console.log('skuId', skuId);
console.log('purchaseError', purchaseError);
console.log('purchases', purchases);
(event: NamiPaywallEvent) => {
console.log('event', event);
},
);
}
Expand Down
81 changes: 23 additions & 58 deletions src/NamiCampaignManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
import {
LaunchCampaignError,
NamiCampaign,
NamiPaywallAction,
NamiPurchase,
NamiPaywallActionHandler,
NamiPaywallEvent,
PaywallLaunchContext,
} from './types';

Expand All @@ -30,24 +30,7 @@ interface ICampaignManager {
withUrl?: string,
context?: PaywallLaunchContext,
resultCallback?: (success: boolean, error?: LaunchCampaignError) => void,
actionCallback?: (
action: NamiPaywallAction,
campaignId: string,
paywallId: string,
campaignName?: string,
campaignType?: string,
campaignLabel?: string,
campaignUrl?: string,
paywallName?: string,
segmentId?: string,
externalSegmentId?: string,
deeplinkUrl?: string,
skuId?: string,
componentChangeId?: string,
componentChangeName?: string,
purchaseError?: string,
purchases?: NamiPurchase[],
) => void,
actionCallback?: NamiPaywallActionHandler,
) => void;
refresh: () => void;
registerAvailableCampaignsHandler: (
Expand All @@ -71,52 +54,34 @@ export const NamiCampaignManager: ICampaignManager = {
? body.action.substring(5, body.action.length)
: body.action;

const {
action,
campaignId,
paywallId,
campaignName,
campaignType,
campaignLabel,
campaignUrl,
paywallName,
segmentId,
externalSegmentId,
deeplinkUrl,
skuId,
componentChangeId,
componentChangeName,
purchaseError,
purchases,
} = body;
if (actionCallback) {
actionCallback(
action,
campaignId,
paywallId,
campaignName,
campaignType,
campaignLabel,
campaignUrl,
paywallName,
segmentId,
externalSegmentId,
deeplinkUrl,
skuId,
componentChangeId,
componentChangeName,
purchaseError,
purchases,
);
const paywallEvent: NamiPaywallEvent = {
action: body.action,
campaignId: body.campaignId,
campaignName: body.campaignName,
campaignType: body.campaignType,
campaignLabel: body.campaignLabel,
campaignUrl: body.campaignUrl,
paywallId: body.paywallId,
paywallName: body.paywallName,
componentChange: body.componentChange,
segmentId: body.segmentId,
externalSegmentId: body.externalSegmentId,
deeplinkUrl: body.deeplinkUrl,
sku: body.sku,
purchaseError: body.purchaseError,
purchases: body.purchases,
}
actionCallback(paywallEvent)
}
},
);
RNNamiCampaignManager.launch(
label ?? null,
withUrl ?? null,
context ?? null,
resultCallback ?? (() => {}),
actionCallback ?? (() => {}),
resultCallback ?? (() => { }),
actionCallback ?? (() => { }),
);
},

Expand Down
4 changes: 3 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,9 @@ export type NamiPaywallEvent = {
sku?: NamiSKU;
purchaseError?: string;
purchases?: NamiPurchase[];
};
}

export type NamiPaywallActionHandler = (event: NamiPaywallEvent) => void;

export type NamiPaywallComponentChange = {
id?: string;
Expand Down

0 comments on commit 27d05f6

Please sign in to comment.