@thead-vantage/react 2.17.0 → 2.18.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thead-vantage/react",
3
- "version": "2.17.0",
3
+ "version": "2.18.0",
4
4
  "description": "React components and utilities for TheAd Vantage ad platform integration",
5
5
  "main": "./src/index.ts",
6
6
  "module": "./src/index.ts",
@@ -12,6 +12,8 @@ export interface AdBannerProps {
12
12
  userId?: string | null;
13
13
  userSegment?: string | null;
14
14
  className?: string;
15
+ clickMetadata?: Record<string, unknown>; // Optional metadata to send with click events
16
+ impressionMetadata?: Record<string, unknown>; // Optional metadata to send with impression events
15
17
  }
16
18
 
17
19
  export function AdBanner({
@@ -22,6 +24,8 @@ export function AdBanner({
22
24
  userId = null,
23
25
  userSegment = null,
24
26
  className = '',
27
+ clickMetadata,
28
+ impressionMetadata,
25
29
  }: AdBannerProps) {
26
30
  const [ad, setAd] = useState<Ad | null>(null);
27
31
  const [loading, setLoading] = useState(true);
@@ -63,7 +67,7 @@ export function AdBanner({
63
67
  setDevMode(response.dev_mode || false);
64
68
 
65
69
  // Track impression (will be skipped in dev mode)
66
- trackImpression(response.ad.id, apiKey, apiUrl);
70
+ trackImpression(response.ad.id, apiKey, apiUrl, impressionMetadata);
67
71
  } else {
68
72
  // Create a more detailed error message
69
73
  const errorDetails = [];
@@ -111,7 +115,7 @@ export function AdBanner({
111
115
 
112
116
  const handleClick = () => {
113
117
  if (ad) {
114
- trackClick(ad.id, apiKey, apiUrl);
118
+ trackClick(ad.id, apiKey, apiUrl, clickMetadata);
115
119
  // The link will handle navigation
116
120
  }
117
121
  };
package/src/lib/ads.ts CHANGED
@@ -430,8 +430,9 @@ export function collectFingerprint(): Fingerprint {
430
430
  * @param adId - The ID of the ad being tracked
431
431
  * @param apiKey - The API key for the platform (required for CORS validation and platform identification)
432
432
  * @param apiUrl - Optional API base URL override
433
+ * @param metadata - Optional metadata object to send with the impression event
433
434
  */
434
- export async function trackImpression(adId: string, apiKey: string, apiUrl?: string): Promise<void> {
435
+ export async function trackImpression(adId: string, apiKey: string, apiUrl?: string, metadata?: Record<string, unknown>): Promise<void> {
435
436
  try {
436
437
  if (!apiKey) {
437
438
  console.warn('[AdBanner] Cannot track impression: API key is required');
@@ -482,6 +483,7 @@ export async function trackImpression(adId: string, apiKey: string, apiUrl?: str
482
483
  action: 'impression',
483
484
  adId,
484
485
  fingerprint: collectFingerprint(), // Include fingerprint data for fraud detection
486
+ ...(metadata && { metadata }), // Include metadata if provided
485
487
  }),
486
488
  });
487
489
 
@@ -519,8 +521,9 @@ export async function trackImpression(adId: string, apiKey: string, apiUrl?: str
519
521
  * @param adId - The ID of the ad being tracked
520
522
  * @param apiKey - The API key for the platform (required for CORS validation and platform identification)
521
523
  * @param apiUrl - Optional API base URL override
524
+ * @param metadata - Optional metadata object to send with the click event
522
525
  */
523
- export async function trackClick(adId: string, apiKey: string, apiUrl?: string): Promise<void> {
526
+ export async function trackClick(adId: string, apiKey: string, apiUrl?: string, metadata?: Record<string, unknown>): Promise<void> {
524
527
  try {
525
528
  if (!apiKey) {
526
529
  console.warn('[AdBanner] Cannot track click: API key is required');
@@ -571,6 +574,7 @@ export async function trackClick(adId: string, apiKey: string, apiUrl?: string):
571
574
  action: 'click',
572
575
  adId,
573
576
  fingerprint: collectFingerprint(), // Include fingerprint data for fraud detection
577
+ ...(metadata && { metadata }), // Include metadata if provided
574
578
  }),
575
579
  });
576
580