@thealteroffice/react-native-adgeist 0.0.20 → 0.0.22
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/Adgeist.podspec +1 -1
- package/README.md +70 -521
- package/android/build.gradle +6 -3
- package/android/generated/java/com/adgeist/NativeAdgeistSpec.java +11 -11
- package/android/generated/java/com/facebook/react/viewmanagers/HTML5AdNativeComponentManagerDelegate.java +55 -0
- package/android/generated/java/com/facebook/react/viewmanagers/HTML5AdNativeComponentManagerInterface.java +24 -0
- package/android/generated/jni/RNAdgeistSpec-generated.cpp +12 -12
- package/android/generated/jni/react/renderer/components/RNAdgeistSpec/ComponentDescriptors.cpp +22 -0
- package/android/generated/jni/react/renderer/components/RNAdgeistSpec/ComponentDescriptors.h +24 -0
- package/android/generated/jni/react/renderer/components/RNAdgeistSpec/EventEmitters.cpp +60 -0
- package/android/generated/jni/react/renderer/components/RNAdgeistSpec/EventEmitters.h +49 -0
- package/android/generated/jni/react/renderer/components/RNAdgeistSpec/Props.cpp +28 -0
- package/android/generated/jni/react/renderer/components/RNAdgeistSpec/Props.h +52 -0
- package/android/generated/jni/react/renderer/components/RNAdgeistSpec/RNAdgeistSpecJSI-generated.cpp +14 -22
- package/android/generated/jni/react/renderer/components/RNAdgeistSpec/RNAdgeistSpecJSI.h +36 -36
- package/android/generated/jni/react/renderer/components/RNAdgeistSpec/ShadowNodes.cpp +17 -0
- package/android/generated/jni/react/renderer/components/RNAdgeistSpec/ShadowNodes.h +32 -0
- package/android/generated/jni/react/renderer/components/RNAdgeistSpec/States.cpp +16 -0
- package/android/generated/jni/react/renderer/components/RNAdgeistSpec/States.h +29 -0
- package/android/src/main/java/com/adgeist/AdgeistPackage.kt +8 -7
- package/android/src/main/java/com/adgeist/components/HTML5AdViewManagerImpl.kt +125 -0
- package/android/src/main/java/com/adgeist/modules/AdgeistImpl.kt +114 -0
- package/android/src/main/java/com/adgeist/utils/CreativeExtensions.kt +151 -0
- package/android/src/newarch/java/com/Adgeist.kt +119 -0
- package/android/src/newarch/java/com/HTML5AdViewManager.kt +77 -0
- package/android/src/oldarch/java/com/Adgeist.kt +132 -0
- package/android/src/oldarch/java/com/HTML5AdViewManager.kt +63 -0
- package/ios/Adgeist-Bridging-Header.h +3 -0
- package/ios/Adgeist.h +1 -1
- package/ios/Adgeist.mm +71 -65
- package/ios/AdgeistImpl.swift +127 -132
- package/ios/NativeHTML5AdManager.h +9 -0
- package/ios/NativeHTML5AdManager.mm +178 -0
- package/ios/NativeHTML5AdView.swift +136 -0
- package/ios/generated/RNAdgeistSpec/ComponentDescriptors.cpp +22 -0
- package/ios/generated/RNAdgeistSpec/ComponentDescriptors.h +24 -0
- package/ios/generated/RNAdgeistSpec/EventEmitters.cpp +60 -0
- package/ios/generated/RNAdgeistSpec/EventEmitters.h +49 -0
- package/ios/generated/RNAdgeistSpec/Props.cpp +28 -0
- package/ios/generated/RNAdgeistSpec/Props.h +52 -0
- package/ios/generated/RNAdgeistSpec/RCTComponentViewHelpers.h +65 -0
- package/ios/generated/RNAdgeistSpec/RNAdgeistSpec-generated.mm +17 -17
- package/ios/generated/RNAdgeistSpec/RNAdgeistSpec.h +17 -25
- package/ios/generated/RNAdgeistSpec/ShadowNodes.cpp +17 -0
- package/ios/generated/RNAdgeistSpec/ShadowNodes.h +32 -0
- package/ios/generated/RNAdgeistSpec/States.cpp +16 -0
- package/ios/generated/RNAdgeistSpec/States.h +29 -0
- package/ios/generated/RNAdgeistSpecJSI-generated.cpp +14 -22
- package/ios/generated/RNAdgeistSpecJSI.h +36 -36
- package/lib/module/cdpclient/index.js +1 -25
- package/lib/module/cdpclient/index.js.map +1 -1
- package/lib/module/components/HTML5AdView.js +128 -0
- package/lib/module/components/HTML5AdView.js.map +1 -0
- package/lib/module/components/{BannerAd.js → deprecated/BannerAdView.js} +50 -79
- package/lib/module/components/deprecated/BannerAdView.js.map +1 -0
- package/lib/module/components/{ConsentModal.js → deprecated/ConsentModal.js} +2 -2
- package/lib/module/components/deprecated/ConsentModal.js.map +1 -0
- package/lib/module/constants.js +14 -0
- package/lib/module/constants.js.map +1 -0
- package/lib/module/index.js +3 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/{components → providers}/AdgeistProvider.js +10 -35
- package/lib/module/providers/AdgeistProvider.js.map +1 -0
- package/lib/module/specs/HTML5AdNativeComponent.ts +46 -0
- package/lib/module/specs/NativeAdgeist.js.map +1 -0
- package/lib/module/types/AdSize.js +2 -0
- package/lib/module/types/AdSize.js.map +1 -0
- package/lib/module/types/CPMAdResponse.js +2 -0
- package/lib/module/types/CPMAdResponse.js.map +1 -0
- package/lib/module/types/FixedAdResponse.js +2 -0
- package/lib/module/types/FixedAdResponse.js.map +1 -0
- package/lib/module/types/HTML5AdNativeComponentProps.js +4 -0
- package/lib/module/types/HTML5AdNativeComponentProps.js.map +1 -0
- package/lib/module/types/Provider.js +2 -0
- package/lib/module/types/Provider.js.map +1 -0
- package/lib/typescript/src/cdpclient/index.d.ts +1 -21
- package/lib/typescript/src/cdpclient/index.d.ts.map +1 -1
- package/lib/typescript/src/components/HTML5AdView.d.ts +3 -0
- package/lib/typescript/src/components/HTML5AdView.d.ts.map +1 -0
- package/lib/typescript/src/components/deprecated/BannerAdView.d.ts +17 -0
- package/lib/typescript/src/components/deprecated/BannerAdView.d.ts.map +1 -0
- package/lib/typescript/src/components/deprecated/ConsentModal.d.ts.map +1 -0
- package/lib/typescript/src/constants.d.ts +10 -0
- package/lib/typescript/src/constants.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +3 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/providers/AdgeistProvider.d.ts +9 -0
- package/lib/typescript/src/providers/AdgeistProvider.d.ts.map +1 -0
- package/lib/typescript/src/specs/HTML5AdNativeComponent.d.ts +29 -0
- package/lib/typescript/src/specs/HTML5AdNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeAdgeist.d.ts +28 -0
- package/lib/typescript/src/specs/NativeAdgeist.d.ts.map +1 -0
- package/lib/typescript/src/types/AdSize.d.ts +5 -0
- package/lib/typescript/src/types/AdSize.d.ts.map +1 -0
- package/lib/typescript/src/types/CPMAdResponse.d.ts +25 -0
- package/lib/typescript/src/types/CPMAdResponse.d.ts.map +1 -0
- package/lib/typescript/src/types/FixedAdResponse.d.ts +50 -0
- package/lib/typescript/src/types/FixedAdResponse.d.ts.map +1 -0
- package/lib/typescript/src/types/HTML5AdNativeComponentProps.d.ts +24 -0
- package/lib/typescript/src/types/HTML5AdNativeComponentProps.d.ts.map +1 -0
- package/lib/typescript/src/types/Provider.d.ts +16 -0
- package/lib/typescript/src/types/Provider.d.ts.map +1 -0
- package/package.json +8 -3
- package/react-native.config.js +1 -1
- package/src/cdpclient/index.ts +1 -21
- package/src/components/HTML5AdView.tsx +161 -0
- package/src/components/{BannerAd.tsx → deprecated/BannerAdView.tsx} +80 -115
- package/src/components/{ConsentModal.tsx → deprecated/ConsentModal.tsx} +2 -2
- package/src/constants.ts +8 -0
- package/src/index.tsx +4 -2
- package/src/{components → providers}/AdgeistProvider.tsx +26 -60
- package/src/specs/HTML5AdNativeComponent.ts +46 -0
- package/src/{NativeAdgeist.ts → specs/NativeAdgeist.ts} +26 -25
- package/src/types/AdSize.ts +4 -0
- package/src/types/CPMAdResponse.ts +26 -0
- package/src/types/FixedAdResponse.ts +51 -0
- package/src/types/HTML5AdNativeComponentProps.ts +28 -0
- package/src/types/Provider.ts +16 -0
- package/android/src/main/AndroidManifestNew.xml +0 -2
- package/android/src/main/java/com/adgeist/implementation/AdgeistModuleImpl.kt +0 -252
- package/android/src/newarch/java/com/AdgeistModule.kt +0 -135
- package/android/src/oldarch/java/com/AdgeistModule.kt +0 -148
- package/ios/adgeist-Bridging-Header.h +0 -1
- package/lib/module/NativeAdgeist.js.map +0 -1
- package/lib/module/components/AdgeistProvider.js.map +0 -1
- package/lib/module/components/BannerAd.js.map +0 -1
- package/lib/module/components/ConsentModal.js.map +0 -1
- package/lib/typescript/src/NativeAdgeist.d.ts +0 -28
- package/lib/typescript/src/NativeAdgeist.d.ts.map +0 -1
- package/lib/typescript/src/components/AdgeistProvider.d.ts +0 -50
- package/lib/typescript/src/components/AdgeistProvider.d.ts.map +0 -1
- package/lib/typescript/src/components/BannerAd.d.ts +0 -64
- package/lib/typescript/src/components/BannerAd.d.ts.map +0 -1
- package/lib/typescript/src/components/ConsentModal.d.ts.map +0 -1
- /package/lib/module/{NativeAdgeist.js → specs/NativeAdgeist.js} +0 -0
- /package/lib/typescript/src/components/{ConsentModal.d.ts → deprecated/ConsentModal.d.ts} +0 -0
package/src/cdpclient/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Adgeist, { type UserDetails, type Event } from '../NativeAdgeist';
|
|
1
|
+
import Adgeist, { type UserDetails, type Event } from '../specs/NativeAdgeist';
|
|
2
2
|
|
|
3
3
|
class AdgeistError extends Error {
|
|
4
4
|
code?: string;
|
|
@@ -11,11 +11,6 @@ class AdgeistError extends Error {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* Sets user details in the Adgeist SDK
|
|
16
|
-
* @param userDetails - User details object
|
|
17
|
-
* @throws AdgeistError if the operation fails
|
|
18
|
-
*/
|
|
19
14
|
export const setUserDetails = (userDetails: UserDetails): void => {
|
|
20
15
|
try {
|
|
21
16
|
Adgeist.setUserDetails(userDetails);
|
|
@@ -26,11 +21,6 @@ export const setUserDetails = (userDetails: UserDetails): void => {
|
|
|
26
21
|
}
|
|
27
22
|
};
|
|
28
23
|
|
|
29
|
-
/**
|
|
30
|
-
* Logs an event in the Adgeist SDK
|
|
31
|
-
* @param event - Event object to log
|
|
32
|
-
* @throws AdgeistError if the event is invalid or logging fails
|
|
33
|
-
*/
|
|
34
24
|
export const logEvent = (event: Event): void => {
|
|
35
25
|
if (!event || typeof event !== 'object') {
|
|
36
26
|
throw new AdgeistError('Event must be a valid object');
|
|
@@ -44,11 +34,6 @@ export const logEvent = (event: Event): void => {
|
|
|
44
34
|
}
|
|
45
35
|
};
|
|
46
36
|
|
|
47
|
-
/**
|
|
48
|
-
* Retrieves the consent status from the Adgeist SDK
|
|
49
|
-
* @returns Promise resolving to 'ACCEPTED' or 'DENIED'
|
|
50
|
-
* @throws AdgeistError if the operation fails
|
|
51
|
-
*/
|
|
52
37
|
export const getConsentStatus = async (): Promise<'ACCEPTED' | 'DENIED'> => {
|
|
53
38
|
try {
|
|
54
39
|
const status = await Adgeist.getConsentStatus();
|
|
@@ -62,11 +47,6 @@ export const getConsentStatus = async (): Promise<'ACCEPTED' | 'DENIED'> => {
|
|
|
62
47
|
}
|
|
63
48
|
};
|
|
64
49
|
|
|
65
|
-
/**
|
|
66
|
-
* Updates the consent status in the Adgeist SDK
|
|
67
|
-
* @param consent - Boolean indicating user consent
|
|
68
|
-
* @throws AdgeistError if the operation fails
|
|
69
|
-
*/
|
|
70
50
|
export const updateConsentStatus = (consent: boolean): void => {
|
|
71
51
|
try {
|
|
72
52
|
Adgeist.updateConsentStatus(consent);
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useRef,
|
|
3
|
+
useCallback,
|
|
4
|
+
useImperativeHandle,
|
|
5
|
+
forwardRef,
|
|
6
|
+
useEffect,
|
|
7
|
+
useState,
|
|
8
|
+
useMemo,
|
|
9
|
+
} from 'react';
|
|
10
|
+
import type { ViewStyle, DimensionValue } from 'react-native';
|
|
11
|
+
|
|
12
|
+
import { useAdgeistContext } from '../providers/AdgeistProvider';
|
|
13
|
+
import HTML5AdNativeComponent, {
|
|
14
|
+
Commands,
|
|
15
|
+
} from '../specs/HTML5AdNativeComponent';
|
|
16
|
+
import type {
|
|
17
|
+
HTML5AdNativeComponentProps,
|
|
18
|
+
HTML5AdRequest,
|
|
19
|
+
HTML5AdViewRef,
|
|
20
|
+
} from '../types/HTML5AdNativeComponentProps';
|
|
21
|
+
import { AdSizes } from '../constants';
|
|
22
|
+
|
|
23
|
+
export const HTML5AdView = forwardRef<
|
|
24
|
+
HTML5AdViewRef,
|
|
25
|
+
HTML5AdNativeComponentProps & HTML5AdRequest
|
|
26
|
+
>(
|
|
27
|
+
(
|
|
28
|
+
{
|
|
29
|
+
adUnitID,
|
|
30
|
+
adIsResponsive,
|
|
31
|
+
adSize,
|
|
32
|
+
adType,
|
|
33
|
+
onAdLoaded,
|
|
34
|
+
onAdFailedToLoad,
|
|
35
|
+
onAdOpened,
|
|
36
|
+
onAdClosed,
|
|
37
|
+
onAdClicked,
|
|
38
|
+
},
|
|
39
|
+
ref
|
|
40
|
+
) => {
|
|
41
|
+
const { isTestEnvironment } = useAdgeistContext();
|
|
42
|
+
|
|
43
|
+
const nativeRef = useRef<any>(null);
|
|
44
|
+
const [isViewReady, setIsViewReady] = useState(false);
|
|
45
|
+
const pendingLoadRef = useRef<HTML5AdRequest | null>(null);
|
|
46
|
+
|
|
47
|
+
const dimensions = useMemo<{
|
|
48
|
+
width: DimensionValue;
|
|
49
|
+
height: DimensionValue;
|
|
50
|
+
}>(() => {
|
|
51
|
+
const width: DimensionValue = adSize?.width ?? '100%';
|
|
52
|
+
const height: DimensionValue = adSize?.height ?? '100%';
|
|
53
|
+
return { width, height };
|
|
54
|
+
}, [adSize?.width, adSize?.height]);
|
|
55
|
+
|
|
56
|
+
const containerStyle = useMemo<ViewStyle>(
|
|
57
|
+
() => ({
|
|
58
|
+
width: dimensions.width,
|
|
59
|
+
height: dimensions.height,
|
|
60
|
+
}),
|
|
61
|
+
[dimensions]
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const loadAdInternal = useCallback(
|
|
65
|
+
(request: HTML5AdRequest = { isTestMode: isTestEnvironment }) => {
|
|
66
|
+
if (!nativeRef.current) {
|
|
67
|
+
console.warn('HTML5AdView: Cannot load ad, native view not ready');
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const finalRequest = {
|
|
72
|
+
...request,
|
|
73
|
+
isTestMode: request.isTestMode ?? isTestEnvironment,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
Commands.loadAd(nativeRef.current, finalRequest.isTestMode);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (__DEV__) {
|
|
80
|
+
console.warn('HTML5AdView: Error loading ad:', error);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
[isTestEnvironment]
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const handleNativeRef = useCallback((ref: any) => {
|
|
88
|
+
nativeRef.current = ref;
|
|
89
|
+
|
|
90
|
+
if (ref) {
|
|
91
|
+
// Mark as ready in the next animation frame (ensures layout pass completed)
|
|
92
|
+
requestAnimationFrame(() => {
|
|
93
|
+
setIsViewReady(true);
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
setIsViewReady(false);
|
|
97
|
+
}
|
|
98
|
+
}, []);
|
|
99
|
+
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
if (isViewReady && adUnitID) {
|
|
102
|
+
const request: HTML5AdRequest = { isTestMode: isTestEnvironment };
|
|
103
|
+
if (pendingLoadRef.current) {
|
|
104
|
+
loadAdInternal(pendingLoadRef.current);
|
|
105
|
+
pendingLoadRef.current = null;
|
|
106
|
+
} else {
|
|
107
|
+
loadAdInternal(request);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}, [isViewReady, adUnitID, isTestEnvironment, loadAdInternal]);
|
|
111
|
+
|
|
112
|
+
useImperativeHandle(
|
|
113
|
+
ref,
|
|
114
|
+
() => ({
|
|
115
|
+
loadAd: (adRequest?: HTML5AdRequest) => {
|
|
116
|
+
const request = adRequest || { isTestMode: isTestEnvironment };
|
|
117
|
+
|
|
118
|
+
if (isViewReady && nativeRef.current) {
|
|
119
|
+
loadAdInternal(request);
|
|
120
|
+
} else {
|
|
121
|
+
pendingLoadRef.current = request;
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
destroy: () => {
|
|
125
|
+
if (nativeRef.current) {
|
|
126
|
+
try {
|
|
127
|
+
Commands.destroy(nativeRef.current);
|
|
128
|
+
} catch (e) {
|
|
129
|
+
console.warn('Error destroying ad view:', e);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
}),
|
|
134
|
+
[isViewReady, isTestEnvironment, loadAdInternal]
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
if (__DEV__) {
|
|
138
|
+
console.log('[HTML5AdView]', { adUnitID, adSize, adType, isViewReady });
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<HTML5AdNativeComponent
|
|
143
|
+
ref={handleNativeRef}
|
|
144
|
+
style={containerStyle}
|
|
145
|
+
// Required Props, it will take values from React Component props
|
|
146
|
+
adUnitID={adUnitID}
|
|
147
|
+
adSize={adIsResponsive ? AdSizes.Responsive : adSize}
|
|
148
|
+
adIsResponsive={adIsResponsive}
|
|
149
|
+
adType={adType}
|
|
150
|
+
// Required Event Callbacks
|
|
151
|
+
onAdLoaded={onAdLoaded}
|
|
152
|
+
onAdFailedToLoad={onAdFailedToLoad}
|
|
153
|
+
onAdOpened={onAdOpened}
|
|
154
|
+
onAdClosed={onAdClosed}
|
|
155
|
+
onAdClicked={onAdClicked}
|
|
156
|
+
/>
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
HTML5AdView.displayName = 'HTML5AdView';
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module BannerAd
|
|
3
|
-
* @description A React Native component for displaying banner and video ads with robust error handling and analytics.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
1
|
import React, { useCallback, useEffect, useState, useRef } from 'react';
|
|
7
2
|
import {
|
|
8
3
|
Image,
|
|
@@ -15,81 +10,37 @@ import {
|
|
|
15
10
|
Dimensions,
|
|
16
11
|
} from 'react-native';
|
|
17
12
|
import Video from 'react-native-video';
|
|
18
|
-
import Adgeist from '
|
|
19
|
-
import { useAdgeistContext } from '
|
|
20
|
-
import { normalizeUrl } from '
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* Interface for ad data structure
|
|
24
|
-
*/
|
|
25
|
-
interface AdData {
|
|
26
|
-
id: string;
|
|
27
|
-
bidId: string;
|
|
28
|
-
cur: string;
|
|
29
|
-
seatBid: SeatBid[];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Interface for seat bid data
|
|
34
|
-
*/
|
|
35
|
-
interface SeatBid {
|
|
36
|
-
bidId: string;
|
|
37
|
-
bid: Bid[];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Interface for individual bid
|
|
42
|
-
*/
|
|
43
|
-
interface Bid {
|
|
44
|
-
id: string;
|
|
45
|
-
impId: string;
|
|
46
|
-
price: number;
|
|
47
|
-
ext: BidExtension;
|
|
48
|
-
}
|
|
13
|
+
import Adgeist from '../../specs/NativeAdgeist';
|
|
14
|
+
import { useAdgeistContext } from '../../providers/AdgeistProvider';
|
|
15
|
+
import { normalizeUrl } from '../../utilities';
|
|
16
|
+
import type { FIXEDADRESPONSE } from '../../types/FixedAdResponse';
|
|
17
|
+
import type { CPMADRESPONSE } from '../../types/CPMAdResponse';
|
|
49
18
|
|
|
50
|
-
/**
|
|
51
|
-
* Interface for bid extension data
|
|
52
|
-
*/
|
|
53
|
-
interface BidExtension {
|
|
54
|
-
creativeUrl: string;
|
|
55
|
-
ctaUrl: string;
|
|
56
|
-
creativeTitle: string;
|
|
57
|
-
creativeDescription: string;
|
|
58
|
-
creativeBrandName?: string;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Props for the BannerAd component
|
|
63
|
-
*/
|
|
64
19
|
interface AdBannerProps {
|
|
65
|
-
/** Unique identifier for the ad slot */
|
|
66
20
|
dataAdSlot: string;
|
|
67
|
-
/** Type of ad to display */
|
|
68
21
|
dataSlotType?: 'banner' | 'video';
|
|
69
|
-
|
|
22
|
+
dataBuyType?: 'FIXED' | 'CPM';
|
|
70
23
|
width?: number;
|
|
71
|
-
/** Height of the ad container */
|
|
72
24
|
height?: number;
|
|
73
|
-
/** Enable responsive layout */
|
|
74
25
|
isResponsive?: boolean;
|
|
75
|
-
/** Responsive layout type */
|
|
76
26
|
responsiveType?: 'SQUARE' | 'VERTICAL' | 'WIDE';
|
|
77
|
-
/** Callback for ad load errors */
|
|
78
27
|
onAdLoadError?: (error: Error) => void;
|
|
79
|
-
|
|
80
|
-
onAdLoadSuccess?: (adData: AdData) => void;
|
|
28
|
+
onAdLoadSuccess?: (adData: FIXEDADRESPONSE | CPMADRESPONSE) => void;
|
|
81
29
|
}
|
|
82
30
|
|
|
83
31
|
export const BannerAd: React.FC<AdBannerProps> = ({
|
|
84
32
|
dataAdSlot,
|
|
85
33
|
dataSlotType = 'banner',
|
|
34
|
+
dataBuyType = 'FIXED',
|
|
86
35
|
width = 0,
|
|
87
36
|
height = 0,
|
|
88
37
|
isResponsive = false,
|
|
89
38
|
onAdLoadError,
|
|
90
39
|
onAdLoadSuccess,
|
|
91
40
|
}) => {
|
|
92
|
-
const [adData, setAdData] = useState<
|
|
41
|
+
const [adData, setAdData] = useState<FIXEDADRESPONSE | CPMADRESPONSE | null>(
|
|
42
|
+
null
|
|
43
|
+
);
|
|
93
44
|
const [isMuted, setIsMuted] = useState<boolean>(true);
|
|
94
45
|
const [error, setError] = useState<Error | null>(null);
|
|
95
46
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
|
@@ -107,17 +58,43 @@ export const BannerAd: React.FC<AdBannerProps> = ({
|
|
|
107
58
|
const currentVisibilityRatio = useRef<number>(0);
|
|
108
59
|
const videoRef = useRef<any>(null);
|
|
109
60
|
|
|
110
|
-
const { isInitialized,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
61
|
+
const { isInitialized, isTestEnvironment } = useAdgeistContext();
|
|
62
|
+
|
|
63
|
+
let creativeBrandName;
|
|
64
|
+
let creativeUrl;
|
|
65
|
+
let creativeTitle;
|
|
66
|
+
let creativeDescription;
|
|
67
|
+
let ctaUrl;
|
|
68
|
+
let bidMeta = '';
|
|
69
|
+
|
|
70
|
+
let bidId;
|
|
71
|
+
let campaignId;
|
|
72
|
+
let adSpaceId = dataAdSlot;
|
|
73
|
+
|
|
74
|
+
if (dataBuyType === 'FIXED') {
|
|
75
|
+
creativeTitle = (adData as FIXEDADRESPONSE)?.creatives?.[0]?.title;
|
|
76
|
+
creativeDescription = (adData as FIXEDADRESPONSE)?.creatives?.[0]
|
|
77
|
+
?.description;
|
|
78
|
+
creativeBrandName = (adData as FIXEDADRESPONSE)?.advertiser?.name;
|
|
79
|
+
creativeUrl = (adData as FIXEDADRESPONSE)?.creatives?.[0]?.fileUrl;
|
|
80
|
+
ctaUrl = (adData as FIXEDADRESPONSE)?.creatives?.[0]?.ctaUrl;
|
|
81
|
+
bidMeta = (adData as FIXEDADRESPONSE)?.metaData;
|
|
82
|
+
|
|
83
|
+
bidId = (adData as FIXEDADRESPONSE)?.id;
|
|
84
|
+
campaignId = (adData as FIXEDADRESPONSE)?.campaignId;
|
|
85
|
+
} else {
|
|
86
|
+
let creativeData = (adData as CPMADRESPONSE)?.seatBid?.[0]?.bid?.[0]?.ext;
|
|
87
|
+
|
|
88
|
+
creativeTitle = creativeData?.creativeTitle;
|
|
89
|
+
creativeDescription = creativeData?.creativeDescription;
|
|
90
|
+
creativeBrandName = creativeData?.creativeBrandName;
|
|
91
|
+
creativeUrl = creativeData?.creativeUrl;
|
|
92
|
+
ctaUrl = creativeData?.ctaUrl;
|
|
93
|
+
|
|
94
|
+
bidId = adData?.id;
|
|
95
|
+
campaignId = (adData as CPMADRESPONSE)?.seatBid?.[0]?.bid?.[0]?.id;
|
|
96
|
+
}
|
|
117
97
|
|
|
118
|
-
/**
|
|
119
|
-
* Fetches ad creative data (without tracking impression here)
|
|
120
|
-
*/
|
|
121
98
|
const fetchAd = useCallback(async () => {
|
|
122
99
|
if (!isInitialized) return;
|
|
123
100
|
|
|
@@ -128,14 +105,14 @@ export const BannerAd: React.FC<AdBannerProps> = ({
|
|
|
128
105
|
setHasView(false);
|
|
129
106
|
|
|
130
107
|
const response = await Adgeist.fetchCreative(
|
|
131
|
-
apiKey,
|
|
132
|
-
domain,
|
|
133
108
|
dataAdSlot,
|
|
134
|
-
|
|
109
|
+
dataBuyType,
|
|
135
110
|
isTestEnvironment
|
|
136
111
|
);
|
|
137
112
|
|
|
138
|
-
const creative: { data:
|
|
113
|
+
const creative: { data: FIXEDADRESPONSE | CPMADRESPONSE } = response as {
|
|
114
|
+
data: FIXEDADRESPONSE | CPMADRESPONSE;
|
|
115
|
+
};
|
|
139
116
|
setAdData(creative.data);
|
|
140
117
|
onAdLoadSuccess?.(creative.data);
|
|
141
118
|
} catch (err) {
|
|
@@ -149,18 +126,13 @@ export const BannerAd: React.FC<AdBannerProps> = ({
|
|
|
149
126
|
}
|
|
150
127
|
}, [
|
|
151
128
|
isInitialized,
|
|
152
|
-
|
|
129
|
+
dataBuyType,
|
|
153
130
|
dataAdSlot,
|
|
154
|
-
apiKey,
|
|
155
|
-
domain,
|
|
156
131
|
isTestEnvironment,
|
|
157
132
|
onAdLoadError,
|
|
158
133
|
onAdLoadSuccess,
|
|
159
134
|
]);
|
|
160
135
|
|
|
161
|
-
/**
|
|
162
|
-
* Tracks impression when media (image/video) is fully loaded
|
|
163
|
-
*/
|
|
164
136
|
const trackImpressionOnMediaLoad = useCallback(async () => {
|
|
165
137
|
if (hasImpression || !bidId || !campaignId) return;
|
|
166
138
|
|
|
@@ -170,9 +142,9 @@ export const BannerAd: React.FC<AdBannerProps> = ({
|
|
|
170
142
|
await Adgeist.trackImpression(
|
|
171
143
|
campaignId,
|
|
172
144
|
adSpaceId,
|
|
173
|
-
publisherId,
|
|
174
|
-
apiKey,
|
|
175
145
|
bidId,
|
|
146
|
+
bidMeta,
|
|
147
|
+
dataBuyType,
|
|
176
148
|
isTestEnvironment,
|
|
177
149
|
renderTime
|
|
178
150
|
);
|
|
@@ -186,14 +158,11 @@ export const BannerAd: React.FC<AdBannerProps> = ({
|
|
|
186
158
|
bidId,
|
|
187
159
|
campaignId,
|
|
188
160
|
adSpaceId,
|
|
189
|
-
|
|
190
|
-
|
|
161
|
+
dataBuyType,
|
|
162
|
+
bidMeta,
|
|
191
163
|
isTestEnvironment,
|
|
192
164
|
]);
|
|
193
165
|
|
|
194
|
-
/**
|
|
195
|
-
* Tracks view event for ads when visible for >=1s (banner) or >=2s (video) and >=50% in viewport
|
|
196
|
-
*/
|
|
197
166
|
const trackView = useCallback(async () => {
|
|
198
167
|
if (hasView || !hasImpression || !bidId || !campaignId) return;
|
|
199
168
|
|
|
@@ -210,9 +179,9 @@ export const BannerAd: React.FC<AdBannerProps> = ({
|
|
|
210
179
|
await Adgeist.trackView(
|
|
211
180
|
campaignId,
|
|
212
181
|
adSpaceId,
|
|
213
|
-
publisherId,
|
|
214
|
-
apiKey,
|
|
215
182
|
bidId,
|
|
183
|
+
bidMeta,
|
|
184
|
+
dataBuyType,
|
|
216
185
|
isTestEnvironment,
|
|
217
186
|
currentViewTime,
|
|
218
187
|
visibility,
|
|
@@ -231,23 +200,17 @@ export const BannerAd: React.FC<AdBannerProps> = ({
|
|
|
231
200
|
bidId,
|
|
232
201
|
campaignId,
|
|
233
202
|
adSpaceId,
|
|
234
|
-
|
|
235
|
-
|
|
203
|
+
dataBuyType,
|
|
204
|
+
bidMeta,
|
|
236
205
|
isTestEnvironment,
|
|
237
206
|
dataSlotType,
|
|
238
207
|
]);
|
|
239
208
|
|
|
240
|
-
/**
|
|
241
|
-
* Toggles play/pause state manually
|
|
242
|
-
*/
|
|
243
209
|
const togglePlayPause = useCallback(() => {
|
|
244
210
|
setIsManuallyControlled(true);
|
|
245
211
|
setIsPaused((prev) => !prev);
|
|
246
212
|
}, []);
|
|
247
213
|
|
|
248
|
-
/**
|
|
249
|
-
* Calculates visibility ratio, updates view metrics, and controls video playback
|
|
250
|
-
*/
|
|
251
214
|
const checkVisibility = useCallback(() => {
|
|
252
215
|
if (!adRef.current || !hasImpression) return;
|
|
253
216
|
|
|
@@ -290,7 +253,6 @@ export const BannerAd: React.FC<AdBannerProps> = ({
|
|
|
290
253
|
}
|
|
291
254
|
}
|
|
292
255
|
|
|
293
|
-
// Only check for view tracking if view event hasn't been tracked yet
|
|
294
256
|
if (
|
|
295
257
|
!hasView &&
|
|
296
258
|
viewTime.current >= (dataSlotType === 'video' ? 2000 : 1000) &&
|
|
@@ -308,23 +270,26 @@ export const BannerAd: React.FC<AdBannerProps> = ({
|
|
|
308
270
|
isManuallyControlled,
|
|
309
271
|
]);
|
|
310
272
|
|
|
311
|
-
/**
|
|
312
|
-
* Handles ad click and sends click analytics
|
|
313
|
-
*/
|
|
314
273
|
const handleClick = useCallback(async () => {
|
|
315
|
-
if (
|
|
274
|
+
if (
|
|
275
|
+
!adData ||
|
|
276
|
+
(dataBuyType == 'CPM' && !(adData as CPMADRESPONSE).seatBid.length) ||
|
|
277
|
+
!bidId ||
|
|
278
|
+
!campaignId
|
|
279
|
+
)
|
|
280
|
+
return;
|
|
316
281
|
|
|
317
282
|
try {
|
|
318
283
|
Adgeist.trackClick(
|
|
319
284
|
campaignId,
|
|
320
285
|
adSpaceId,
|
|
321
|
-
publisherId,
|
|
322
|
-
apiKey,
|
|
323
286
|
bidId,
|
|
287
|
+
bidMeta,
|
|
288
|
+
dataBuyType,
|
|
324
289
|
isTestEnvironment
|
|
325
290
|
);
|
|
326
291
|
|
|
327
|
-
await Linking.openURL(normalizeUrl(
|
|
292
|
+
await Linking.openURL(normalizeUrl(ctaUrl as string));
|
|
328
293
|
} catch (err) {
|
|
329
294
|
console.error('Failed to handle ad click:', err);
|
|
330
295
|
}
|
|
@@ -333,10 +298,10 @@ export const BannerAd: React.FC<AdBannerProps> = ({
|
|
|
333
298
|
bidId,
|
|
334
299
|
campaignId,
|
|
335
300
|
adSpaceId,
|
|
336
|
-
|
|
337
|
-
|
|
301
|
+
bidMeta,
|
|
302
|
+
dataBuyType,
|
|
338
303
|
isTestEnvironment,
|
|
339
|
-
|
|
304
|
+
ctaUrl,
|
|
340
305
|
]);
|
|
341
306
|
|
|
342
307
|
useEffect(() => {
|
|
@@ -370,7 +335,7 @@ export const BannerAd: React.FC<AdBannerProps> = ({
|
|
|
370
335
|
);
|
|
371
336
|
}
|
|
372
337
|
|
|
373
|
-
if (
|
|
338
|
+
if (creativeUrl || error) return null;
|
|
374
339
|
|
|
375
340
|
return (
|
|
376
341
|
<TouchableWithoutFeedback
|
|
@@ -389,7 +354,7 @@ export const BannerAd: React.FC<AdBannerProps> = ({
|
|
|
389
354
|
<TouchableWithoutFeedback onPress={handleClick}>
|
|
390
355
|
<Image
|
|
391
356
|
style={styles.creative}
|
|
392
|
-
source={{ uri:
|
|
357
|
+
source={{ uri: creativeUrl }}
|
|
393
358
|
accessibilityLabel="Ad Creative"
|
|
394
359
|
resizeMode="contain"
|
|
395
360
|
onLoad={trackImpressionOnMediaLoad}
|
|
@@ -404,7 +369,7 @@ export const BannerAd: React.FC<AdBannerProps> = ({
|
|
|
404
369
|
<TouchableWithoutFeedback onPress={handleClick}>
|
|
405
370
|
<Video
|
|
406
371
|
ref={videoRef}
|
|
407
|
-
source={{ uri:
|
|
372
|
+
source={{ uri: creativeUrl }}
|
|
408
373
|
resizeMode="contain"
|
|
409
374
|
style={{ width: '100%', height: '100%' }}
|
|
410
375
|
repeat={true}
|
|
@@ -448,22 +413,22 @@ export const BannerAd: React.FC<AdBannerProps> = ({
|
|
|
448
413
|
<View style={styles.adContent}>
|
|
449
414
|
<View style={styles.contentContainer}>
|
|
450
415
|
<Text style={styles.title} numberOfLines={1} ellipsizeMode="tail">
|
|
451
|
-
{
|
|
416
|
+
{creativeTitle}
|
|
452
417
|
</Text>
|
|
453
418
|
<Text
|
|
454
419
|
style={styles.description}
|
|
455
420
|
numberOfLines={1}
|
|
456
421
|
ellipsizeMode="tail"
|
|
457
422
|
>
|
|
458
|
-
{
|
|
423
|
+
{creativeDescription}
|
|
459
424
|
</Text>
|
|
460
|
-
{
|
|
425
|
+
{creativeBrandName && (
|
|
461
426
|
<Text
|
|
462
427
|
style={styles.brandName}
|
|
463
428
|
numberOfLines={1}
|
|
464
429
|
ellipsizeMode="tail"
|
|
465
430
|
>
|
|
466
|
-
{
|
|
431
|
+
{creativeBrandName || 'The Brand Name'}
|
|
467
432
|
</Text>
|
|
468
433
|
)}
|
|
469
434
|
</View>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
3
|
import { StyleSheet, View, Text, Pressable } from 'react-native';
|
|
4
|
-
import { useAdgeistContext } from '
|
|
5
|
-
import Adgeist from '
|
|
4
|
+
import { useAdgeistContext } from '../../providers/AdgeistProvider';
|
|
5
|
+
import Adgeist from '../../specs/NativeAdgeist';
|
|
6
6
|
|
|
7
7
|
interface ConsentModalPropsType {}
|
|
8
8
|
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AdSize } from './types/AdSize';
|
|
2
|
+
|
|
3
|
+
export const AdSizes = {
|
|
4
|
+
custom: (width: number, height: number): AdSize => ({ width, height }),
|
|
5
|
+
Responsive: { width: -1, height: -1 },
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const HTML_5_AD_NATIVE_COMPONENT_NAME = 'HTML5AdNativeComponent';
|
package/src/index.tsx
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './components/
|
|
1
|
+
export * from './providers/AdgeistProvider';
|
|
2
|
+
export * from './components/HTML5AdView';
|
|
3
|
+
|
|
4
|
+
export * from './components/deprecated/BannerAdView';
|
|
3
5
|
|
|
4
6
|
export * from './cdpclient/index';
|