@surfside/ads-core 2.0.17 → 2.0.19

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.
Files changed (57) hide show
  1. package/lib/cjs/Api.js +11 -7
  2. package/lib/cjs/Api.js.map +1 -1
  3. package/lib/cjs/BuildInfo.js +1 -1
  4. package/lib/cjs/helpers/Functions.js +8 -0
  5. package/lib/cjs/helpers/Functions.js.map +1 -0
  6. package/lib/cjs/helpers/index.js +1 -0
  7. package/lib/cjs/helpers/index.js.map +1 -1
  8. package/lib/cjs/helpers/response/Carousel.js +50 -37
  9. package/lib/cjs/helpers/response/Carousel.js.map +1 -1
  10. package/lib/cjs/helpers/response/ProductCard.js +62 -9
  11. package/lib/cjs/helpers/response/ProductCard.js.map +1 -1
  12. package/lib/cjs/models/retail/Configuration.js +10 -0
  13. package/lib/cjs/models/retail/Configuration.js.map +1 -1
  14. package/lib/cjs/models/rtb/NativeRequest.js +6 -1
  15. package/lib/cjs/models/rtb/NativeRequest.js.map +1 -1
  16. package/lib/cjs/services/Bidder.js +1 -0
  17. package/lib/cjs/services/Bidder.js.map +1 -1
  18. package/lib/cjs/services/Category.js +17 -17
  19. package/lib/cjs/services/Category.js.map +1 -1
  20. package/lib/cjs/services/Tracker.js +71 -0
  21. package/lib/cjs/services/Tracker.js.map +1 -0
  22. package/lib/cjs/services/index.js +1 -0
  23. package/lib/cjs/services/index.js.map +1 -1
  24. package/lib/esm/Api.js +11 -7
  25. package/lib/esm/Api.js.map +1 -1
  26. package/lib/esm/BuildInfo.js +1 -1
  27. package/lib/esm/helpers/Functions.js +3 -0
  28. package/lib/esm/helpers/Functions.js.map +1 -0
  29. package/lib/esm/helpers/index.js +1 -0
  30. package/lib/esm/helpers/index.js.map +1 -1
  31. package/lib/esm/helpers/response/Carousel.js +50 -37
  32. package/lib/esm/helpers/response/Carousel.js.map +1 -1
  33. package/lib/esm/helpers/response/ProductCard.js +61 -9
  34. package/lib/esm/helpers/response/ProductCard.js.map +1 -1
  35. package/lib/esm/models/retail/Configuration.js +8 -1
  36. package/lib/esm/models/retail/Configuration.js.map +1 -1
  37. package/lib/esm/models/rtb/NativeRequest.js +6 -1
  38. package/lib/esm/models/rtb/NativeRequest.js.map +1 -1
  39. package/lib/esm/services/Bidder.js +1 -0
  40. package/lib/esm/services/Bidder.js.map +1 -1
  41. package/lib/esm/services/Category.js +17 -17
  42. package/lib/esm/services/Category.js.map +1 -1
  43. package/lib/esm/services/Tracker.js +67 -0
  44. package/lib/esm/services/Tracker.js.map +1 -0
  45. package/lib/esm/services/index.js +1 -0
  46. package/lib/esm/services/index.js.map +1 -1
  47. package/lib/types/Api.d.ts +8 -1
  48. package/lib/types/helpers/Functions.d.ts +2 -0
  49. package/lib/types/helpers/index.d.ts +1 -0
  50. package/lib/types/helpers/response/Carousel.d.ts +5 -4
  51. package/lib/types/helpers/response/ProductCard.d.ts +20 -7
  52. package/lib/types/models/retail/Configuration.d.ts +12 -1
  53. package/lib/types/models/rtb/BidResponse.d.ts +1 -0
  54. package/lib/types/models/rtb/NativeRequest.d.ts +2 -0
  55. package/lib/types/services/Tracker.d.ts +25 -0
  56. package/lib/types/services/index.d.ts +1 -0
  57. package/package.json +1 -1
@@ -0,0 +1,67 @@
1
+ import { Ctx } from './Logger';
2
+ export const InitTrackerService = (logger, accountId, siteId, locationId, channelId, windowInfo, userAgent, geo, device, userId, host) => {
3
+ const initTracker = (path, eventName) => (product) => async (context) => {
4
+ const log = Ctx(logger)?.with('recommended tracker').with(eventName);
5
+ try {
6
+ log?.info('Calling event tracker');
7
+ const url = new URL(`${windowInfo.protocol}//${host}/${path}`);
8
+ url.searchParams.set('location_id', locationId);
9
+ url.searchParams.set('item_id', product.id ?? 'undefined');
10
+ url.searchParams.set('next_type', context?.nextType ?? 'page');
11
+ url.searchParams.set('recommendation_model', context?.recommend ?? 'top-products');
12
+ url.searchParams.set('recommendation_page', String(context?.page ?? 1));
13
+ url.searchParams.set('recommendation_position_absolute', String(context?.positionAbsolute ?? 1));
14
+ url.searchParams.set('recommendation_position_relative', String(context?.positionRelative ?? 1));
15
+ url.searchParams.set('recommendation_value', String(context?.recommendationValue ?? 1));
16
+ url.searchParams.set('strategy', context?.strategy ?? 'hybrid');
17
+ url.searchParams.set('zone_id', context?.zoneId ?? 'undefined');
18
+ url.searchParams.set('account_id', accountId);
19
+ url.searchParams.set('event_name', eventName);
20
+ if (geo !== undefined) {
21
+ url.searchParams.set('geo_city', geo.city);
22
+ url.searchParams.set('geo_country', geo.country);
23
+ url.searchParams.set('geo_metro', geo.city);
24
+ url.searchParams.set('geo_region', geo.region);
25
+ url.searchParams.set('geo_utcoffset', String(geo.utcoffset));
26
+ url.searchParams.set('geo_zip', geo.zip);
27
+ url.searchParams.set('ip', geo.ip);
28
+ url.searchParams.set('lat', String(geo.coords.latitude));
29
+ url.searchParams.set('lon', String(geo.coords.longitude));
30
+ }
31
+ url.searchParams.set('isp', 'undefined');
32
+ if (device !== undefined) {
33
+ url.searchParams.set('device_type', String(device.devicetype));
34
+ url.searchParams.set('make', device.make ?? 'undefined');
35
+ url.searchParams.set('model', device.model ?? 'undefined');
36
+ url.searchParams.set('os', device.os ?? 'undefined');
37
+ url.searchParams.set('osv', device.osv ?? 'undefined');
38
+ }
39
+ url.searchParams.set('pub_bundle', windowInfo.host);
40
+ url.searchParams.set('pub_channel_id', channelId);
41
+ url.searchParams.set('pub_domain', windowInfo.host);
42
+ url.searchParams.set('pub_id', siteId);
43
+ url.searchParams.set('pub_name', windowInfo.host);
44
+ url.searchParams.set('pub_site_id', siteId);
45
+ url.searchParams.set('pub_store_id', locationId);
46
+ url.searchParams.set('pub_zone', context?.zoneId ?? 'undefined');
47
+ url.searchParams.set('ua', userAgent);
48
+ if (userId !== undefined) {
49
+ url.searchParams.set('user_id', userId ?? 'undefined');
50
+ }
51
+ const finalUrl = url.toString();
52
+ log?.debug(finalUrl);
53
+ await fetch(url);
54
+ }
55
+ catch (e) {
56
+ log?.error('Failed to call tracker. Got', e);
57
+ }
58
+ };
59
+ return {
60
+ recommended: {
61
+ getClickTracker: initTracker('rec/clk', 'click'),
62
+ getImpressionTracker: initTracker('rec/imp', 'imp'),
63
+ getAddToCartTracker: initTracker('rec/atc', 'atc')
64
+ }
65
+ };
66
+ };
67
+ //# sourceMappingURL=Tracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tracker.js","sourceRoot":"src/","sources":["services/Tracker.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,GAAG,EAAgB,MAAM,UAAU,CAAC;AAwC7C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAC9B,MAA2B,EAC3B,SAAiB,EACjB,MAAc,EACd,UAAkB,EAClB,SAAiB,EACjB,UAAyC,EACzC,SAAiB,EACjB,GAA4B,EAC5B,MAA2B,EAC3B,MAA0B,EAC1B,IAAY,EACU,EAAE;IACxB,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,SAAiB,EAAE,EAAE,CACpD,CAAC,OAA4B,EAAE,EAAE,CAC7B,KAAK,EAAE,OAA0B,EAAE,EAAE;QACjC,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAErE,IAAI,CAAC;YACD,GAAG,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAC;YACnC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,UAAU,CAAC,QAAQ,KAAK,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC;YAE/D,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;YAChD,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,IAAI,WAAW,CAAC,CAAC;YAC3D,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,EAAE,QAAQ,IAAI,MAAM,CAAC,CAAC;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EAAE,KAAK,CAAC;YACnD,mBAAmB,EAAE,WAAW,CAAC,SAAS,EAAE,KAAK,CAAC;SACrD;KACJ,CAAC;AACN,CAAC,CAAC"}
@@ -9,4 +9,5 @@ export * from './Recommender';
9
9
  export * from './Memo';
10
10
  export * from './Template';
11
11
  export * from './Dynamic';
12
+ export * from './Tracker';
12
13
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"src/","sources":["services/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"src/","sources":["services/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"}
@@ -6,6 +6,7 @@ import { type BuildHybridCarouselFn, type BuildHybridCarouselFromInitialBidFn, t
6
6
  import { type EvaluateClickthroughTemplateFn, type EvaluateProductCardTemplateFn } from './services/Template';
7
7
  import { type BuildDynamicZoneRequestFn, type GetDynamicZoneFn } from './services/Dynamic';
8
8
  import { type GenerateCategoriesFn } from './services/Category';
9
+ import { type InitTrackerServiceFn, type IProductTrackerService } from './services/Tracker';
9
10
  export declare const PROD_BIDDER = "//bid.surfside.io/rtb/bids/surfside";
10
11
  export declare const PROD_CONFIGURATION_SERVICE = "//r.surfside.io";
11
12
  export declare const PROD_SPONSORED_PRODUCT_FEED = "//creative.surfside.io";
@@ -48,6 +49,11 @@ export interface ISurfsideApi {
48
49
  * Generates categories for the site
49
50
  */
50
51
  generateCategories: GenerateCategoriesFn;
52
+ /**
53
+ * Creates a set of trackers from a product input. Builds a URL with all relevant info from the trackers
54
+ * and returns functions to call when the relevant events fire
55
+ */
56
+ trackers: IProductTrackerService;
51
57
  /**
52
58
  * A handlebars runtime instance, for evaluating templates
53
59
  */
@@ -145,6 +151,7 @@ export declare function InitSurfAdsCoreInternal(internalApiDto: {
145
151
  generateSponsoredProductCardResponse: GenerateSponsoredProductCardResponseFn;
146
152
  evaluateProductCardTemplate: EvaluateProductCardTemplateFn;
147
153
  evaluateClickthroughTemplate: EvaluateClickthroughTemplateFn;
154
+ initTrackerService: InitTrackerServiceFn;
148
155
  handlebars: typeof Handlebars;
149
156
  windowInfo: INativeTemplateDelegateWindow;
150
157
  screenInfo: IScreen;
@@ -158,7 +165,7 @@ export declare function InitSurfAdsCoreInternal(internalApiDto: {
158
165
  locationId: string;
159
166
  userId: string | undefined;
160
167
  }): AsyncResult<ISurfsideApi>;
161
- export declare const InitSurfAdsCoreServices: (logger: ILogger | undefined, bidderServiceUrl: string, configurationServiceUrl: string, productFeedUrl: string, recommendedProductFeedUrl: string, recommenderServiceUrl: string, dynamicZoneServiceUrl: string, windowInfo: INativeTemplateDelegateWindow, screenInfo: IScreen, navigator: INavigator, mobile: boolean, ip: string | undefined, geoProviderToken: string | undefined, accountId: string, siteId: string, channelId: string, locationId: string, userId: string | undefined) => AsyncResult<ISurfsideApi>;
168
+ export declare const InitSurfAdsCoreServices: (logger: ILogger | undefined, bidderServiceUrl: string, configurationServiceUrl: string, productFeedUrl: string, recommendedProductFeedUrl: string, recommenderServiceUrl: string, dynamicZoneServiceUrl: string, windowInfo: INativeTemplateDelegateWindow, screenInfo: IScreen, navigator: INavigator, mobile: boolean, ip: string | undefined, geoProviderToken: string | undefined, accountId: string, siteId: string, channelId: string, locationId: string, userId: string | undefined, initTrackerService?: InitTrackerServiceFn) => AsyncResult<ISurfsideApi>;
162
169
  export declare const InitSurfAdsCoreSSR: (windowInfo: INativeTemplateDelegateWindow, screen: IScreen, navigator: INavigator, mobile: boolean, ip: string, geoProviderToken: string, accountId: string, siteId: string, channelId: string, locationId: string, userId: string | undefined, logger?: ILogger) => AsyncResult<ISurfsideApi>;
163
170
  export declare const InitSurfAdsCore: (channelId: string, accountId: string, siteId: string, locationId: string, userId: string | undefined, logger?: ILogger) => AsyncResult<ISurfsideApi>;
164
171
  export declare class MissingConfigurationError extends Error {
@@ -0,0 +1,2 @@
1
+ export declare const Nothing: () => undefined;
2
+ export declare const AsyncNothing: () => Promise<undefined>;
@@ -5,3 +5,4 @@ export * from './Handlebars';
5
5
  export * from './TryGet';
6
6
  export * from './Window';
7
7
  export * from './Generator';
8
+ export * from './Functions';
@@ -1,6 +1,7 @@
1
- import type { IBid, IBidRequest } from '../../models';
1
+ import { type IBid, type IBidRequest } from '../../models';
2
2
  import { type ILogger, type NonPersonalRecommenderFn, type PersonalRecommenderFn, type RequestBidsFn, type Result } from '../../services';
3
3
  import { type EvaluateClickthroughTemplateFn } from '../../services/Template';
4
+ import { type IProductTrackerService } from '../../services/Tracker';
4
5
  import type { GenerateSponsoredProductCardResponseFn, IBuiltProductCardResponse } from './ProductCard';
5
6
  export type BuildSponsoredCarouselFn = (request: IBidRequest) => Result<IBuiltCarousel>;
6
7
  export type BuildSponsoredCarouselFromInitialBidFn = (request: IBidRequest, initialBid: IBid) => Result<IBuiltCarousel>;
@@ -42,9 +43,9 @@ export interface IPastPurchasesProductRecommender {
42
43
  export type ProductRecommender = ITopProductRecommender | IForYouProductRecommender | IPastPurchasesProductRecommender;
43
44
  export declare const BuildSponsoredCarousel: (logger: ILogger | undefined, requestBids: RequestBidsFn, generateProductCardResponse: GenerateSponsoredProductCardResponseFn, request: IBidRequest) => Result<IBuiltCarousel>;
44
45
  export declare const BuildSponsoredCarouselFromInitialBid: (logger: ILogger | undefined, requestBids: RequestBidsFn, generateProductCardResponse: GenerateSponsoredProductCardResponseFn, request: IBidRequest, initialBid: IBid) => Result<IBuiltCarousel>;
45
- export declare const BuildRecommendedCarousel: (logger: ILogger | undefined, evaluateClickthroughTemplate: EvaluateClickthroughTemplateFn, topProductGenerator: NonPersonalRecommenderFn, forYouProductGenerator: PersonalRecommenderFn, pastPurchasesProductGenerator: PersonalRecommenderFn, userId: string | undefined, recommenderType: PublicRecommenderType) => Result<IBuiltCarousel>;
46
- export declare const BuildHybridCarousel: (logger: ILogger | undefined, evaluateClickthroughTemplate: EvaluateClickthroughTemplateFn, requestBids: RequestBidsFn, generateProductCardResponse: GenerateSponsoredProductCardResponseFn, topProductGenerator: NonPersonalRecommenderFn, forYouProductGenerator: PersonalRecommenderFn, pastPurchasesProductGenerator: PersonalRecommenderFn, userId: string | undefined, recommenderType: PublicRecommenderType, request: IBidRequest) => Result<IBuiltCarousel>;
47
- export declare const BuildHybridCarouselFromInitialBid: (logger: ILogger | undefined, evaluateClickthroughTemplate: EvaluateClickthroughTemplateFn, requestBids: RequestBidsFn, generateProductCardResponse: GenerateSponsoredProductCardResponseFn, topProductGenerator: NonPersonalRecommenderFn, forYouProductGenerator: PersonalRecommenderFn, pastPurchasesProductGenerator: PersonalRecommenderFn, userId: string | undefined, recommenderType: PublicRecommenderType, request: IBidRequest, initialBid: IBid) => Result<IBuiltCarousel>;
46
+ export declare const BuildRecommendedCarousel: (logger: ILogger | undefined, evaluateClickthroughTemplate: EvaluateClickthroughTemplateFn, topProductGenerator: NonPersonalRecommenderFn, forYouProductGenerator: PersonalRecommenderFn, pastPurchasesProductGenerator: PersonalRecommenderFn, userId: string | undefined, trackers: IProductTrackerService, recommenderType: PublicRecommenderType) => Result<IBuiltCarousel>;
47
+ export declare const BuildHybridCarousel: (logger: ILogger | undefined, evaluateClickthroughTemplate: EvaluateClickthroughTemplateFn, requestBids: RequestBidsFn, generateProductCardResponse: GenerateSponsoredProductCardResponseFn, topProductGenerator: NonPersonalRecommenderFn, forYouProductGenerator: PersonalRecommenderFn, pastPurchasesProductGenerator: PersonalRecommenderFn, userId: string | undefined, trackers: IProductTrackerService, recommenderType: PublicRecommenderType, request: IBidRequest) => Result<IBuiltCarousel>;
48
+ export declare const BuildHybridCarouselFromInitialBid: (logger: ILogger | undefined, evaluateClickthroughTemplate: EvaluateClickthroughTemplateFn, requestBids: RequestBidsFn, generateProductCardResponse: GenerateSponsoredProductCardResponseFn, topProductGenerator: NonPersonalRecommenderFn, forYouProductGenerator: PersonalRecommenderFn, pastPurchasesProductGenerator: PersonalRecommenderFn, userId: string | undefined, trackers: IProductTrackerService, recommenderType: PublicRecommenderType, request: IBidRequest, initialBid: IBid) => Result<IBuiltCarousel>;
48
49
  export declare class InvalidRecommenderTypeError extends Error {
49
50
  type: string;
50
51
  constructor(type: string);
@@ -1,22 +1,34 @@
1
- import { type IBid, type ICompiledPublisherConfiguration, type INativeResponse, type INativeTemplateDelegateWindow, type IProductInformation } from '../../models';
1
+ import { type IBid, type ICompiledPublisherConfiguration, type INativeResponse, type INativeTemplateDelegateWindow, type IProductInformation, type ProductCallbackExtras } from '../../models';
2
2
  import { type AsyncResult, type GetAllSponsoredProductFromNativeIdFn, type ILogger } from '../../services';
3
+ import { type ProductTrackerCallback } from '../../services/Tracker';
3
4
  import { type IBuiltResponse } from './BuiltResponse';
4
5
  export type BuildAllSponsoredProductCardResponsesFn = (bids: IBid[]) => AsyncResult<IBuiltProductCardBidResponse[]>;
5
6
  export type GenerateSponsoredProductCardResponseFn = (bids: IBid[]) => AsyncGenerator<IBuiltProductCardBidResponse>;
6
- export interface ITracker {
7
- type: number;
7
+ export interface IPixelTracker {
8
+ type: 'pixel';
8
9
  url: string;
9
10
  }
10
- export interface IPixelTracker extends ITracker {
11
- type: 1;
11
+ export interface IScriptTracker {
12
+ type: 'script';
13
+ src: string;
14
+ }
15
+ export interface ICallbackTracker {
16
+ type: 'callback';
17
+ callback: ProductTrackerCallback;
12
18
  }
13
- export interface IScriptTracker extends ITracker {
14
- type: 2;
19
+ export type TrackerObject = IPixelTracker | IScriptTracker | ICallbackTracker;
20
+ export interface ITracker {
21
+ type: number;
22
+ url: string;
15
23
  }
16
24
  export interface ITrackerObject {
25
+ /** @deprecated */
17
26
  win: string;
27
+ /** @deprecated */
18
28
  imp: string[];
29
+ /** @deprecated */
19
30
  others: ITracker[];
31
+ namedTrackers: Record<string, TrackerObject[]>;
20
32
  }
21
33
  export type IBuiltProductCardBidResponse = IBuiltResponse & IBuiltProductCardResponse & {
22
34
  native: INativeResponse;
@@ -47,3 +59,4 @@ export declare class MissingProductIdError extends Error {
47
59
  readonly native: INativeResponse;
48
60
  constructor(bid: IBid, native: INativeResponse);
49
61
  }
62
+ export declare const NamedTrackersToCallbacks: (namedTrackers: Record<string, TrackerObject[]> | undefined) => ProductCallbackExtras;
@@ -1,6 +1,15 @@
1
1
  import type { IDynamicZone, IProductInformation } from '../../models';
2
2
  import type { ICompiledCategoryPublisherConfiguration, ICompiledCategoryPublisherConfigurationDTO } from './Category';
3
- export type ProductCallback = (e: Event, product: IProductInformation) => void;
3
+ export type TrackerCallback = () => Promise<void>;
4
+ export type ProductCallbackExtras = {
5
+ trackers: {
6
+ addToCart: TrackerCallback;
7
+ imp: TrackerCallback;
8
+ click: TrackerCallback;
9
+ [key: string]: TrackerCallback;
10
+ };
11
+ };
12
+ export type ProductCallback = (e: Event, product: IProductInformation, extras: ProductCallbackExtras) => void;
4
13
  export type Callbacks = Record<string, ProductCallback>;
5
14
  export type TemplateDelegate = (context: IProductContext) => string;
6
15
  export interface INativeTemplateDelegateWindow {
@@ -55,6 +64,7 @@ export interface ICompiledPublisherConfigurationSettingsDTO {
55
64
  productFeedEnabled: boolean;
56
65
  sponsoredByEnabled?: boolean;
57
66
  defaultImage?: string;
67
+ strictCategoryMatching?: boolean;
58
68
  }
59
69
  export interface ICompiledPublisherConfigurationDTO {
60
70
  templates: ICompiledPublisherConfigurationTemplatesDTO;
@@ -68,3 +78,4 @@ export interface ICompiledPublisherConfiguration {
68
78
  category: ICompiledCategoryPublisherConfiguration;
69
79
  dynamicZones?: Record<string, IDynamicZone>;
70
80
  }
81
+ export declare const DefaultProductCallbackExtras: () => ProductCallbackExtras;
@@ -1,5 +1,6 @@
1
1
  export interface IBidExtensions extends Record<string, any> {
2
2
  primaryCategory?: string;
3
+ originalCategories?: string[];
3
4
  }
4
5
  export interface IBid {
5
6
  id: string;
@@ -67,6 +67,8 @@ export declare const EventTypes: {
67
67
  readonly ViewableMRC50: 2;
68
68
  readonly ViewableMRC100: 3;
69
69
  readonly ViewableVIDEO50: 4;
70
+ readonly Click: 500;
71
+ readonly AddToCart: 501;
70
72
  };
71
73
  /**
72
74
  * The context of the page for the native ad unit, i.e what type of content is being displayed
@@ -0,0 +1,25 @@
1
+ import type { RecommenderType } from '../helpers';
2
+ import type { IDevice, IGeoContext, INativeTemplateDelegateWindow, IProductInformation } from '../models';
3
+ import { type ILogger } from './Logger';
4
+ export interface ICarouselContext {
5
+ nextType: 'page' | 'product';
6
+ recommend: RecommenderType;
7
+ strategy: 'sponsored' | 'hybrid' | 'recommended';
8
+ page?: number;
9
+ positionAbsolute?: number;
10
+ positionRelative?: number;
11
+ recommendationValue: number;
12
+ zoneId: string;
13
+ }
14
+ export type ProductTrackerCallback = (context?: ICarouselContext) => Promise<void>;
15
+ export type ProductTrackerInitializer = (product: IProductInformation) => ProductTrackerCallback;
16
+ export interface IRecommendedTrackerService {
17
+ getClickTracker: ProductTrackerInitializer;
18
+ getAddToCartTracker: ProductTrackerInitializer;
19
+ getImpressionTracker: ProductTrackerInitializer;
20
+ }
21
+ export interface IProductTrackerService {
22
+ recommended: IRecommendedTrackerService;
23
+ }
24
+ export type InitTrackerServiceFn = (logger: ILogger | undefined, accountId: string, siteId: string, locationId: string, channelId: string, windowInfo: INativeTemplateDelegateWindow, userAgent: string, geo: IGeoContext | undefined, device: IDevice | undefined, userId: string | undefined, host: string) => IProductTrackerService;
25
+ export declare const InitTrackerService: (logger: ILogger | undefined, accountId: string, siteId: string, locationId: string, channelId: string, windowInfo: INativeTemplateDelegateWindow, userAgent: string, geo: IGeoContext | undefined, device: IDevice | undefined, userId: string | undefined, host: string) => IProductTrackerService;
@@ -9,3 +9,4 @@ export * from './Recommender';
9
9
  export * from './Memo';
10
10
  export * from './Template';
11
11
  export * from './Dynamic';
12
+ export * from './Tracker';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@surfside/ads-core",
3
- "version": "2.0.17",
3
+ "version": "2.0.19",
4
4
  "module": "./lib/esm/index.js",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "types": "./lib/types/index.d.ts",