@surfside/ads-react 0.1.0 → 0.1.2
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/README.md +127 -127
- package/lib/cjs/components/SurfsideBanner.js +71 -0
- package/lib/cjs/components/SurfsideBanner.js.map +1 -0
- package/lib/cjs/components/SurfsideCarousel.js +103 -0
- package/lib/cjs/components/SurfsideCarousel.js.map +1 -0
- package/lib/cjs/components/SurfsideDynamicZone.js +131 -0
- package/lib/cjs/components/SurfsideDynamicZone.js.map +1 -0
- package/lib/cjs/components/SurfsideProduct.js +3 -0
- package/lib/cjs/components/SurfsideProduct.js.map +1 -0
- package/lib/cjs/components/SurfsideVideo.js +82 -0
- package/lib/cjs/components/SurfsideVideo.js.map +1 -0
- package/lib/cjs/components/index.js +23 -0
- package/lib/cjs/components/index.js.map +1 -0
- package/lib/cjs/hooks/index.js +22 -0
- package/lib/cjs/hooks/index.js.map +1 -0
- package/lib/cjs/hooks/useSurfsideBanner.js +215 -0
- package/lib/cjs/hooks/useSurfsideBanner.js.map +1 -0
- package/lib/cjs/hooks/useSurfsideDynamicZone.js +202 -0
- package/lib/cjs/hooks/useSurfsideDynamicZone.js.map +1 -0
- package/lib/cjs/hooks/useSurfsideProducts.js +366 -0
- package/lib/cjs/hooks/useSurfsideProducts.js.map +1 -0
- package/lib/cjs/hooks/useSurfsideVideo.js +295 -0
- package/lib/cjs/hooks/useSurfsideVideo.js.map +1 -0
- package/lib/cjs/index.js +20 -16325
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/provider/SurfsideContextProvider.js +158 -0
- package/lib/cjs/provider/SurfsideContextProvider.js.map +1 -0
- package/lib/cjs/provider/index.js +19 -0
- package/lib/cjs/provider/index.js.map +1 -0
- package/lib/cjs/utils/Analytics.js +181 -0
- package/lib/cjs/utils/Analytics.js.map +1 -0
- package/lib/cjs/utils/index.js +18 -0
- package/lib/cjs/utils/index.js.map +1 -0
- package/lib/esm/components/SurfsideBanner.js +67 -0
- package/lib/esm/components/SurfsideBanner.js.map +1 -0
- package/lib/esm/components/SurfsideCarousel.js +99 -0
- package/lib/esm/components/SurfsideCarousel.js.map +1 -0
- package/lib/esm/components/SurfsideDynamicZone.js +126 -0
- package/lib/esm/components/SurfsideDynamicZone.js.map +1 -0
- package/lib/esm/components/SurfsideProduct.js +2 -0
- package/lib/esm/components/SurfsideProduct.js.map +1 -0
- package/lib/esm/components/SurfsideVideo.js +78 -0
- package/lib/esm/components/SurfsideVideo.js.map +1 -0
- package/lib/esm/components/index.js +7 -0
- package/lib/esm/components/index.js.map +1 -0
- package/lib/esm/hooks/index.js +6 -0
- package/lib/esm/hooks/index.js.map +1 -0
- package/lib/esm/hooks/useSurfsideBanner.js +209 -0
- package/lib/esm/hooks/useSurfsideBanner.js.map +1 -0
- package/lib/esm/hooks/useSurfsideDynamicZone.js +197 -0
- package/lib/esm/hooks/useSurfsideDynamicZone.js.map +1 -0
- package/lib/esm/hooks/useSurfsideProducts.js +359 -0
- package/lib/esm/hooks/useSurfsideProducts.js.map +1 -0
- package/lib/esm/hooks/useSurfsideVideo.js +289 -0
- package/lib/esm/hooks/useSurfsideVideo.js.map +1 -0
- package/lib/esm/index.js +4 -16299
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/provider/SurfsideContextProvider.js +151 -0
- package/lib/esm/provider/SurfsideContextProvider.js.map +1 -0
- package/lib/esm/provider/index.js +3 -0
- package/lib/esm/provider/index.js.map +1 -0
- package/lib/esm/utils/Analytics.js +171 -0
- package/lib/esm/utils/Analytics.js.map +1 -0
- package/lib/esm/utils/index.js +2 -0
- package/lib/esm/utils/index.js.map +1 -0
- package/lib/types/components/SurfsideBanner.d.ts +1 -2
- package/lib/types/components/SurfsideVideo.d.ts +0 -1
- package/lib/types/hooks/useSurfsideBanner.d.ts +1 -1
- package/package.json +13 -6
- package/lib/types/hooks/useSurfDynamicZone.d.ts +0 -7
- package/lib/types/types.d.ts +0 -33
- package/lib/types/utils/analytics.d.ts +0 -58
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,6CAA2B;AAC3B,0CAAwB"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.NotInProviderError = exports.InvalidStateError = exports.SurfsideProvider = exports.useSurfsideContext = void 0;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const ads_core_1 = require("@surfside/ads-core");
|
|
8
|
+
const ads_core_web_1 = require("@surfside/ads-core-web");
|
|
9
|
+
const ads_core_mock_1 = require("@surfside/ads-core-mock");
|
|
10
|
+
;
|
|
11
|
+
;
|
|
12
|
+
;
|
|
13
|
+
const SurfsideContext = (0, react_1.createContext)(undefined);
|
|
14
|
+
/**
|
|
15
|
+
* Returns the Surfside Context state, or throws an error if the context failed to return at all (i.e, you are calling
|
|
16
|
+
* useSurfsideContext outside of SurfsideProvider node)
|
|
17
|
+
*
|
|
18
|
+
* @throws {Error} If the context failed to initialize.
|
|
19
|
+
*/
|
|
20
|
+
const useSurfsideContext = () => {
|
|
21
|
+
const context = (0, react_1.useContext)(SurfsideContext);
|
|
22
|
+
if (context === undefined) {
|
|
23
|
+
return {
|
|
24
|
+
error: (0, ads_core_1.Err)(new NotInProviderError),
|
|
25
|
+
status: 'error',
|
|
26
|
+
isReady: false,
|
|
27
|
+
setLocationId: () => void 0,
|
|
28
|
+
setUserId: () => void 0,
|
|
29
|
+
isInitializing: false,
|
|
30
|
+
hasError: true
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return context;
|
|
34
|
+
};
|
|
35
|
+
exports.useSurfsideContext = useSurfsideContext;
|
|
36
|
+
const searchHasString = (str) => typeof window !== 'undefined' &&
|
|
37
|
+
window.location.search.toLowerCase().includes(str);
|
|
38
|
+
/**
|
|
39
|
+
* The provider for the Surfside ads context.
|
|
40
|
+
*
|
|
41
|
+
* @see {@link ISurfsideProviderProps}
|
|
42
|
+
*/
|
|
43
|
+
const SurfsideProvider = ({ accountId, channelId, siteId, locationId: cfgLocationId, userId: cfgUserId, config, onError, children, logger: userLogger }) => {
|
|
44
|
+
const [api, setApi] = (0, react_1.useState)();
|
|
45
|
+
const [isInitializing, setIsInitializing] = (0, react_1.useState)(true);
|
|
46
|
+
const [error, setError] = (0, react_1.useState)();
|
|
47
|
+
const [locationId, setLocationId] = (0, react_1.useState)(cfgLocationId);
|
|
48
|
+
const [userId, setUserId] = (0, react_1.useState)(cfgUserId);
|
|
49
|
+
const debug = config?.debug ?? searchHasString('surf_debug=true');
|
|
50
|
+
const mock = config?.mock ?? searchHasString('surf_mock=true');
|
|
51
|
+
const logger = (0, react_1.useMemo)(() => (0, ads_core_1.Ctx)(userLogger ?? (debug ? (0, ads_core_1.InitLogger)() : undefined)), [userLogger]);
|
|
52
|
+
const log = (0, ads_core_1.Ctx)(logger)?.with('SurfsideProvider');
|
|
53
|
+
log?.info('Initializing Surfside provider');
|
|
54
|
+
(0, react_1.useEffect)(() => {
|
|
55
|
+
let cancel = false;
|
|
56
|
+
log?.info('Checking initialization state');
|
|
57
|
+
if (locationId === undefined) {
|
|
58
|
+
setLoadingState();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const initializerPromise = !mock
|
|
62
|
+
? (0, ads_core_web_1.InitSurfAdsWeb)(accountId, siteId, channelId, locationId, userId, logger)
|
|
63
|
+
: (0, ads_core_web_1.InitSurfAdsWebInternal)((0, ads_core_mock_1.InitSurfAdsCoreMock)(accountId, channelId, siteId, locationId, userId, (0, ads_core_1.InitLogger)()));
|
|
64
|
+
initializerPromise.then(web => {
|
|
65
|
+
if (cancel) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (!web.ok) {
|
|
69
|
+
setErrorState(web);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
setSuccessState(web.value);
|
|
73
|
+
});
|
|
74
|
+
return () => {
|
|
75
|
+
cancel = true;
|
|
76
|
+
};
|
|
77
|
+
}, [locationId, accountId, siteId, channelId, userId, logger]);
|
|
78
|
+
const setLoadingState = () => {
|
|
79
|
+
setIsInitializing(true);
|
|
80
|
+
setError(undefined);
|
|
81
|
+
setApi(undefined);
|
|
82
|
+
};
|
|
83
|
+
const setErrorState = (err) => {
|
|
84
|
+
setIsInitializing(false);
|
|
85
|
+
setError(err);
|
|
86
|
+
setApi(undefined);
|
|
87
|
+
};
|
|
88
|
+
const setSuccessState = (api) => {
|
|
89
|
+
setIsInitializing(false);
|
|
90
|
+
setError(undefined);
|
|
91
|
+
setApi(api);
|
|
92
|
+
};
|
|
93
|
+
const contextValue = (0, ads_core_1.GetValueOrThrow)((0, ads_core_1.TryDo)(() => {
|
|
94
|
+
if (isInitializing) { // Loading state
|
|
95
|
+
return {
|
|
96
|
+
isInitializing: true,
|
|
97
|
+
status: 'initializing',
|
|
98
|
+
isReady: false,
|
|
99
|
+
error: undefined,
|
|
100
|
+
hasError: false,
|
|
101
|
+
setLocationId,
|
|
102
|
+
setUserId
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
else if (error !== undefined) { // error state
|
|
106
|
+
return {
|
|
107
|
+
isInitializing: false,
|
|
108
|
+
status: 'error',
|
|
109
|
+
error,
|
|
110
|
+
setLocationId,
|
|
111
|
+
setUserId,
|
|
112
|
+
isReady: false,
|
|
113
|
+
hasError: true
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
else if (api !== undefined) { // success state
|
|
117
|
+
return {
|
|
118
|
+
...api,
|
|
119
|
+
isReady: true,
|
|
120
|
+
status: 'ready',
|
|
121
|
+
setLocationId,
|
|
122
|
+
setUserId,
|
|
123
|
+
hasError: false,
|
|
124
|
+
isInitializing: false
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
else { // error - indeterminate state. Set error state
|
|
128
|
+
return {
|
|
129
|
+
error: (0, ads_core_1.Err)(new InvalidStateError),
|
|
130
|
+
isReady: false,
|
|
131
|
+
isInitializing: false,
|
|
132
|
+
status: 'error',
|
|
133
|
+
setLocationId,
|
|
134
|
+
setUserId,
|
|
135
|
+
hasError: true
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}));
|
|
139
|
+
if (contextValue.status === 'error') {
|
|
140
|
+
onError?.(contextValue.error);
|
|
141
|
+
}
|
|
142
|
+
return ((0, jsx_runtime_1.jsx)(SurfsideContext.Provider, { value: contextValue, children: children }));
|
|
143
|
+
};
|
|
144
|
+
exports.SurfsideProvider = SurfsideProvider;
|
|
145
|
+
class InvalidStateError extends Error {
|
|
146
|
+
constructor() {
|
|
147
|
+
super('Surfside context provider was left in an invalid state. Contact the vendor');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.InvalidStateError = InvalidStateError;
|
|
151
|
+
class NotInProviderError extends Error {
|
|
152
|
+
constructor() {
|
|
153
|
+
super('useSurfsideContext must be used within a SurfsideProvider block. Did you forget to add the provider to' +
|
|
154
|
+
' your App.tsx?');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
exports.NotInProviderError = NotInProviderError;
|
|
158
|
+
//# sourceMappingURL=SurfsideContextProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SurfsideContextProvider.js","sourceRoot":"src/","sources":["provider/SurfsideContextProvider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;AAEb,iCAQe;AAEf,iDAS4B;AAC5B,yDAAsG;AACtG,2DAA8D;AA+D7D,CAAC;AAkDD,CAAC;AAiBD,CAAC;AAUF,MAAM,eAAe,GAAG,IAAA,qBAAa,EACjC,SAAS,CACZ,CAAC;AAEF;;;;;GAKG;AACI,MAAM,kBAAkB,GAAG,GAAyB,EAAE;IACzD,MAAM,OAAO,GAAG,IA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,OAAO,EAAE,KAAK;gBACd,QAAQ,EAAE,IAAI;aACjB,CAAC;QACN,CAAC;aAAM,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC,CAAC,gBAAgB;YAC5C,OAAO;gBACH,GAAG,GAAG;gBACN,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE,OAAO;gBACf,aAAa;gBACb,SAAS;gBACT,QAAQ,EAAE,KAAK;gBACf,cAAc,EAAE,KAAK;aACxB,CAAC;QACN,CAAC;aAAM,CAAC,CAAC,+CAA+C;YACpD,OAAO;gBACH,KAAK,EAAE,IAAA,cAAG,EAAC,IAAI,iBAAiB,CAAC;gBACjC,OAAO,EAAE,KAAK;gBACd,cAAc,EAAE,KAAK;gBACrB,MAAM,EAAE,OAAO;gBACf,aAAa;gBACb,SAAS;gBACT,QAAQ,EAAE,IAAI;aACjB,CAAC;QACN,CAAC;IACL,CAAC,CAAC,CAAC,CAAC;IAEJ,IAAI,YAAY,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;QAClC,OAAO,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,CACH,uBAAC,eAAe,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,YACxC,QAAQ,GACc,CAC9B,CAAC;AACN,CAAC,CAAC;AAzIW,QAAA,gBAAgB,oBAyI3B;AAEF,MAAa,iBAAkB,SAAQ,KAAK;IACxC;QACI,KAAK,CAAC,4EAA4E,CAAC,CAAC;IACxF,CAAC;CACJ;AAJD,8CAIC;AAED,MAAa,kBAAmB,SAAQ,KAAK;IACzC;QACI,KAAK,CAAC,wGAAwG;YAC1G,gBAAgB,CACnB,CAAC;IACN,CAAC;CACJ;AAND,gDAMC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
__exportStar(require("./SurfsideContextProvider"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["provider/index.ts"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;AACb,4DAA0C"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.trackZoneEvent = exports.trackVideoEvent = exports.trackVideoImpression = exports.trackBannerImpression = exports.trackProductImpressions = exports.trackBannerClick = exports.trackProductClick = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Track a product click event
|
|
6
|
+
* @param product The product that was clicked
|
|
7
|
+
* @param zoneId The zone ID where the product was displayed
|
|
8
|
+
* @param callback Optional callback for custom tracking
|
|
9
|
+
*/
|
|
10
|
+
const trackProductClick = (product, zoneId, callback) => {
|
|
11
|
+
const analytics = {
|
|
12
|
+
timestamp: Date.now(),
|
|
13
|
+
zoneId,
|
|
14
|
+
productId: product.id,
|
|
15
|
+
locationId: undefined, // Will be filled by the hook
|
|
16
|
+
};
|
|
17
|
+
// Log the click event
|
|
18
|
+
console.debug('[Surfside Analytics] Product click:', {
|
|
19
|
+
productId: product.id,
|
|
20
|
+
zoneId,
|
|
21
|
+
timestamp: analytics.timestamp,
|
|
22
|
+
});
|
|
23
|
+
// Call the callback if provided
|
|
24
|
+
if (callback !== undefined) {
|
|
25
|
+
callback(product, analytics);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.trackProductClick = trackProductClick;
|
|
29
|
+
/**
|
|
30
|
+
* Track a banner click event
|
|
31
|
+
* @param banner The banner that was clicked
|
|
32
|
+
* @param zoneId The zone ID where the banner was displayed
|
|
33
|
+
* @param callback Optional callback for custom tracking
|
|
34
|
+
*/
|
|
35
|
+
const trackBannerClick = (banner, zoneId, callback) => {
|
|
36
|
+
const analytics = {
|
|
37
|
+
timestamp: Date.now(),
|
|
38
|
+
zoneId,
|
|
39
|
+
bannerId: banner.id,
|
|
40
|
+
locationId: undefined, // Will be filled by the hook
|
|
41
|
+
};
|
|
42
|
+
// Log the click event
|
|
43
|
+
console.debug('[Surfside Analytics] Banner click:', {
|
|
44
|
+
bannerId: banner.id,
|
|
45
|
+
zoneId,
|
|
46
|
+
timestamp: analytics.timestamp,
|
|
47
|
+
});
|
|
48
|
+
// Call the callback if provided
|
|
49
|
+
if (callback !== undefined) {
|
|
50
|
+
callback(analytics);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
exports.trackBannerClick = trackBannerClick;
|
|
54
|
+
/**
|
|
55
|
+
* Track product impressions
|
|
56
|
+
* @param products The products that were impressed
|
|
57
|
+
* @param zoneId The zone ID where the products were displayed
|
|
58
|
+
* @param callback Optional callback for custom tracking
|
|
59
|
+
*/
|
|
60
|
+
const trackProductImpressions = (products, zoneId, callback) => {
|
|
61
|
+
const analytics = {
|
|
62
|
+
timestamp: Date.now(),
|
|
63
|
+
zoneId,
|
|
64
|
+
productIds: products.map(p => p.id).filter(p => p !== undefined),
|
|
65
|
+
locationId: undefined, // Will be filled by the hook
|
|
66
|
+
};
|
|
67
|
+
// Log the impression event
|
|
68
|
+
console.debug('[Surfside Analytics] Product impressions:', {
|
|
69
|
+
productIds: analytics.productIds,
|
|
70
|
+
zoneId,
|
|
71
|
+
timestamp: analytics.timestamp,
|
|
72
|
+
});
|
|
73
|
+
// Call the callback if provided
|
|
74
|
+
if (callback !== undefined) {
|
|
75
|
+
callback(products, analytics);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
exports.trackProductImpressions = trackProductImpressions;
|
|
79
|
+
/**
|
|
80
|
+
* Track banner impressions
|
|
81
|
+
* @param banner The banner that was impressed
|
|
82
|
+
* @param zoneId The zone ID where the banner was displayed
|
|
83
|
+
* @param callback Optional callback for custom tracking
|
|
84
|
+
*/
|
|
85
|
+
const trackBannerImpression = (banner, zoneId, callback) => {
|
|
86
|
+
const analytics = {
|
|
87
|
+
timestamp: Date.now(),
|
|
88
|
+
zoneId,
|
|
89
|
+
bannerId: banner.id,
|
|
90
|
+
locationId: undefined, // Will be filled by the hook
|
|
91
|
+
};
|
|
92
|
+
// Log the impression event
|
|
93
|
+
console.debug('[Surfside Analytics] Banner impression:', {
|
|
94
|
+
bannerId: banner.id,
|
|
95
|
+
zoneId,
|
|
96
|
+
timestamp: analytics.timestamp,
|
|
97
|
+
});
|
|
98
|
+
// Call the callback if provided
|
|
99
|
+
if (callback !== undefined) {
|
|
100
|
+
callback(analytics);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
exports.trackBannerImpression = trackBannerImpression;
|
|
104
|
+
/**
|
|
105
|
+
* Track video impression
|
|
106
|
+
* @param video The video that was impressed
|
|
107
|
+
* @param zoneId The zone ID where the video was displayed
|
|
108
|
+
* @param callback Optional callback for custom tracking
|
|
109
|
+
*/
|
|
110
|
+
const trackVideoImpression = (video, zoneId, callback) => {
|
|
111
|
+
const analytics = {
|
|
112
|
+
timestamp: Date.now(),
|
|
113
|
+
zoneId,
|
|
114
|
+
videoId: video.id,
|
|
115
|
+
locationId: undefined, // Will be filled by the hook
|
|
116
|
+
};
|
|
117
|
+
// Log the impression event
|
|
118
|
+
console.debug('[Surfside Analytics] Video impression:', {
|
|
119
|
+
videoId: video.id,
|
|
120
|
+
zoneId,
|
|
121
|
+
timestamp: analytics.timestamp,
|
|
122
|
+
});
|
|
123
|
+
// Call the callback if provided
|
|
124
|
+
if (callback !== undefined) {
|
|
125
|
+
callback(analytics);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
exports.trackVideoImpression = trackVideoImpression;
|
|
129
|
+
/**
|
|
130
|
+
* Track video events (play, pause, complete, etc.)
|
|
131
|
+
* @param video The video object
|
|
132
|
+
* @param zoneId The zone ID where the video was displayed
|
|
133
|
+
* @param eventType The type of event (play, pause, complete, etc.)
|
|
134
|
+
* @param position Current position in the video (seconds)
|
|
135
|
+
* @param callback Optional callback for custom tracking
|
|
136
|
+
*/
|
|
137
|
+
const trackVideoEvent = (video, zoneId, eventType, position, callback) => {
|
|
138
|
+
const analytics = {
|
|
139
|
+
timestamp: Date.now(),
|
|
140
|
+
zoneId,
|
|
141
|
+
videoId: video.id,
|
|
142
|
+
eventType,
|
|
143
|
+
position,
|
|
144
|
+
locationId: undefined, // Will be filled by the hook
|
|
145
|
+
};
|
|
146
|
+
// Log the event
|
|
147
|
+
console.debug('[Surfside Analytics] Video event:', {
|
|
148
|
+
videoId: video.id,
|
|
149
|
+
eventType,
|
|
150
|
+
zoneId,
|
|
151
|
+
position,
|
|
152
|
+
timestamp: analytics.timestamp,
|
|
153
|
+
});
|
|
154
|
+
// Call the callback if provided
|
|
155
|
+
if (callback !== undefined) {
|
|
156
|
+
callback(analytics);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
exports.trackVideoEvent = trackVideoEvent;
|
|
160
|
+
/**
|
|
161
|
+
* Track zone events (ready, no content, error)
|
|
162
|
+
* @param zoneId The zone ID
|
|
163
|
+
* @param eventType The type of event (ready, no-content, error)
|
|
164
|
+
* @param data Additional data for the event
|
|
165
|
+
* @param callback Optional callback for custom tracking
|
|
166
|
+
*/
|
|
167
|
+
const trackZoneEvent = (zoneId, eventType, data, callback) => {
|
|
168
|
+
// Log the zone event
|
|
169
|
+
console.debug('[Surfside Analytics] Zone event:', {
|
|
170
|
+
zoneId,
|
|
171
|
+
eventType,
|
|
172
|
+
data,
|
|
173
|
+
timestamp: Date.now(),
|
|
174
|
+
});
|
|
175
|
+
// Call the callback if provided
|
|
176
|
+
if (callback !== undefined) {
|
|
177
|
+
callback(eventType, zoneId, data);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
exports.trackZoneEvent = trackZoneEvent;
|
|
181
|
+
//# sourceMappingURL=Analytics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Analytics.js","sourceRoot":"src/","sources":["utils/Analytics.ts"],"names":[],"mappings":";;;AAyBA;;;;;GAKG;AACI,MAAM,iBAAiB,GAAG,CAC7B,OAA4B,EAC5B,MAAc,EACd,QAA6E,EACzE,EAAE;IACN,MAAM,SAAS,GAAoB;QAC/B,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;QACrB,MAAM;QACN,SAAS,EAAE,OAAO,CAAC,EAAE;QACrB,UAAU,EAAE,SAAS,EAAE,6BAA6B;KACvD,CAAC;IAEF,sBAAsB;IACtB,OAAO,CAAC,KAAK,CAAC,qCAAqC,EAAE;QACjD,SAAS,EAAE,OAAO,CAAC,EAAE;QACrB,MAAM;QACN,SAAS,EAAE,SAAS,CAAC,SAAS;KACjC,CAAC,CAAC;IAEH,gCAAgC;IAChC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QACzB,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACjC,CAAC;AACL,CAAC,CAAC;AAvBW,QAAA,iBAAiB,qBAuB5B;AAEF;;;;;GAKG;AACI,MAAM,gBAAgB,GAAG,CAC5B,MAAe,EACf,MAAc,EACd,QAA+C,EAC3C,EAAE;IACN,MAAM,SAAS,GAAoB;QAC/B,SA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GAAG,EAAE;QACrB,MAAM;QACN,OAAO,EAAE,KAAK,CAAC,EAAE;QACjB,SAAS;QACT,QAAQ;QACR,UAAU,EAAE,SAAS,EAAE,6BAA6B;KACvD,CAAC;IAEF,gBAAgB;IAChB,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE;QAC/C,OAAO,EAAE,KAAK,CAAC,EAAE;QACjB,SAAS;QACT,MAAM;QACN,QAAQ;QACR,SAAS,EAAE,SAAS,CAAC,SAAS;KACjC,CAAC,CAAC;IAEH,gCAAgC;IAChC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QACzB,QAAQ,CAAC,SAAS,CAAC,CAAC;IACxB,CAAC;AACL,CAAC,CAAC;AA7BW,QAAA,eAAe,mBA6B1B;AAEF;;;;;;GAMG;AACI,MAAM,cAAc,GAAG,CAC1B,MAAc,EACd,SAA2C,EAC3C,IAA8B,EAC9B,QAAsF,EAClF,EAAE;IACN,qBAAqB;IACrB,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE;QAC9C,MAAM;QACN,SAAS;QACT,IAAI;QACJ,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;KACxB,CAAC,CAAC;IAEH,gCAAgC;IAChC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACtC,CAAC;AACL,CAAC,CAAC;AAlBW,QAAA,cAAc,kBAkBzB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Analytics"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
import { useSurfsideBanner } from '../hooks';
|
|
5
|
+
import { useSurfsideContext } from '../provider';
|
|
6
|
+
import { Ctx } from '@surfside/ads-core';
|
|
7
|
+
import { RenderBanner } from '@surfside/ads-core-web';
|
|
8
|
+
/**
|
|
9
|
+
* SurfsideBanner renders a banner ad using the `useSurfsideBanner` hook. It automatically
|
|
10
|
+
* manages banner fetching, win tracking, and optional UI fallback states.
|
|
11
|
+
*
|
|
12
|
+
* Customize the banner lifecycle using callbacks and optionally inject custom styles
|
|
13
|
+
* or loading/error content.
|
|
14
|
+
*
|
|
15
|
+
* @param {ISurfsideBannerProps} props Props used to configure the banner rendering behavior
|
|
16
|
+
* @returns A responsive ad container that manages display and state transitions
|
|
17
|
+
*/
|
|
18
|
+
export const SurfsideBanner = ({ zoneId, size, enabled = true, renderLoading, renderError, onRender, onWin, onError, }) => {
|
|
19
|
+
const { banner, loading, error } = useSurfsideBanner({
|
|
20
|
+
zoneId,
|
|
21
|
+
size,
|
|
22
|
+
enabled,
|
|
23
|
+
});
|
|
24
|
+
const [renderedBanner, setRenderedBanner] = useState();
|
|
25
|
+
const { logger } = useSurfsideContext();
|
|
26
|
+
const log = Ctx(logger)?.with('SurfsideBanner');
|
|
27
|
+
// call user callback
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (banner !== undefined) {
|
|
30
|
+
log?.info('SurfsideBanner: win tracked', banner.id);
|
|
31
|
+
onWin?.(banner.id);
|
|
32
|
+
}
|
|
33
|
+
}, [banner]);
|
|
34
|
+
// Call render callback
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (banner !== undefined) {
|
|
37
|
+
log?.info('SurfsideBanner: banner rendered', banner.id);
|
|
38
|
+
onRender?.(banner.id);
|
|
39
|
+
}
|
|
40
|
+
}, [banner]);
|
|
41
|
+
// Handle error callback
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (error !== undefined) {
|
|
44
|
+
log?.error('SurfsideBanner: error', error);
|
|
45
|
+
onError?.(error);
|
|
46
|
+
}
|
|
47
|
+
}, [error]);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (banner != undefined) {
|
|
50
|
+
const rendered = RenderBanner(logger, banner);
|
|
51
|
+
if (rendered.ok) {
|
|
52
|
+
setRenderedBanner(rendered.value);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
setRenderedBanner(undefined);
|
|
57
|
+
}
|
|
58
|
+
}, [banner]);
|
|
59
|
+
return (_jsxs("div", { children: [loading && renderLoading?.(), error !== undefined && renderError?.(), banner !== undefined &&
|
|
60
|
+
renderedBanner !== undefined && (_jsx("div", { ref: (ref) => {
|
|
61
|
+
if (ref != undefined) {
|
|
62
|
+
ref.innerHTML = '';
|
|
63
|
+
ref.appendChild(renderedBanner);
|
|
64
|
+
}
|
|
65
|
+
} }))] }));
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=SurfsideBanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|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"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Ctx, TryDoFlat } from '@surfside/ads-core';
|
|
4
|
+
import { useSurfsideContext } from '../provider';
|
|
5
|
+
import { useEffect, useRef, useState } from 'react';
|
|
6
|
+
;
|
|
7
|
+
export const SurfsideCarousel = ({ zoneId, cardMinWidth, carouselLimits, nextType, recommender, requestBuilder, nativeRequestBuilder, enabled = true, strategy }) => {
|
|
8
|
+
const { isReady, error: apiError, hasError, startRequest, defaultNative, buildHybridCarousel, buildSponsoredCarousel, buildRecommendedCarousel, renderCarousel, logger } = useSurfsideContext();
|
|
9
|
+
const log = Ctx(logger)?.with('SurfsideCarousel');
|
|
10
|
+
const [error, setError] = useState();
|
|
11
|
+
const [renderedCarousel, setRenderedCarousel] = useState();
|
|
12
|
+
const ref = useRef(null);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
let cancelled = false;
|
|
15
|
+
if (!isReady || !enabled) {
|
|
16
|
+
if (hasError) {
|
|
17
|
+
setErrorState(apiError);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
setLoadingState();
|
|
21
|
+
}
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const request = (requestBuilder ?? startRequest(zoneId))
|
|
25
|
+
.withNative((nativeRequestBuilder ?? defaultNative())
|
|
26
|
+
.withMetaProduct()
|
|
27
|
+
.build());
|
|
28
|
+
const builtCarousel = TryDoFlat(() => {
|
|
29
|
+
switch (strategy) {
|
|
30
|
+
case 'hybrid': {
|
|
31
|
+
return buildHybridCarousel({
|
|
32
|
+
type: recommender,
|
|
33
|
+
}, request.build());
|
|
34
|
+
}
|
|
35
|
+
case 'recommended': {
|
|
36
|
+
return buildRecommendedCarousel({
|
|
37
|
+
type: recommender
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
case 'sponsored': {
|
|
41
|
+
return buildSponsoredCarousel(request.build());
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
if (!builtCarousel.ok) {
|
|
46
|
+
setErrorState(builtCarousel);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const builtCarouselValue = builtCarousel.value;
|
|
50
|
+
renderCarousel(builtCarouselValue, cardMinWidth, carouselLimits, nextType)
|
|
51
|
+
.then(renderedCarouselResult => {
|
|
52
|
+
if (cancelled) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (!renderedCarouselResult.ok) {
|
|
56
|
+
setErrorState(renderedCarouselResult);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
setSuccessState(renderedCarouselResult.value);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return () => void (cancelled = true);
|
|
64
|
+
}, [isReady, apiError, hasError, strategy, recommender, cardMinWidth, carouselLimits, nextType]);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (ref.current === null || renderedCarousel === undefined) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
ref.current.innerHTML = '';
|
|
70
|
+
ref.current.appendChild(renderedCarousel.element);
|
|
71
|
+
renderedCarousel.init()
|
|
72
|
+
.then(initResult => {
|
|
73
|
+
if (!initResult.ok) {
|
|
74
|
+
setErrorState(initResult);
|
|
75
|
+
if (ref.current !== null) {
|
|
76
|
+
log?.error('First page was null');
|
|
77
|
+
ref.current.innerHTML = '';
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
;
|
|
82
|
+
}, [renderedCarousel]);
|
|
83
|
+
const setErrorState = (error) => {
|
|
84
|
+
setError(error);
|
|
85
|
+
setRenderedCarousel(undefined);
|
|
86
|
+
};
|
|
87
|
+
const setLoadingState = () => {
|
|
88
|
+
setError(undefined);
|
|
89
|
+
};
|
|
90
|
+
const setSuccessState = (renderedCarousel) => {
|
|
91
|
+
setRenderedCarousel(renderedCarousel);
|
|
92
|
+
setError(undefined);
|
|
93
|
+
};
|
|
94
|
+
if (error !== undefined) {
|
|
95
|
+
log?.error(error.error);
|
|
96
|
+
}
|
|
97
|
+
return _jsx("div", { ref: ref });
|
|
98
|
+
};
|
|
99
|
+
//# sourceMappingURL=SurfsideCarousel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SurfsideCarousel.js","sourceRoot":"src/","sources":["components/SurfsideCarousel.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAIH,GAAG,EACH,SAAS,EACZ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAmBnD,CAAC;AAWF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAC7B,MAAM,EACN,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,WAAW,EACX,cAAc,EACd,oBAAoB,EACpB,OAAO,GAAG,IAAI,EACd,QAAQ,EACY,EAAE,EAAE;IACxB,MAAM,EACF,OAAO,EACP,KAAK,EAAE,QAAQ,EACf,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,sBAAsB,EACtB,wBAAwB,EACxB,cAAc,EACd,MAAM,EACT,GAAG,kBAAkB,EAAE,CAAC;IAEzB,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;IAElD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,EAAa,CAAC;IAChD,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,QAAQ,EAAqB,CAAC;IAC9E,MAAM,GAAG,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAEzC,SAAS,CAAC,GAAG,EAAE;QACX,IAAI,SAAS,GAAG,KAAK,CAAC;QACt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