@adtogether/web-sdk 0.1.22 → 0.1.23

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/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
- ## 0.1.22
1
+ ## 0.1.23
2
+
3
+ * **Sync**: Version parity across all AdTogether SDKs.
2
4
 
5
+ ## 0.1.22
3
6
  * **Brand**: Added "Powered by AdTogether" attribution to all Interstitial ad formats.
4
7
  * **Sync**: Unified versioning (0.1.20) across all AdTogether SDKs.
5
8
 
package/README.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # AdTogether Web SDK
2
2
 
3
+ > [!IMPORTANT]
4
+ > **Developer Account Required**: Before integrating the SDK, you must create a developer account at [https://adtogether.relaxsoftwareapps.com](https://adtogether.relaxsoftwareapps.com) to generate your `appId` and configure your ad units. Integration will not work without a valid `appId`.
5
+
6
+ <p align="center">
7
+ <img src="../../public/dashboard.png" width="800" alt="Developer Dashboard">
8
+ </p>
9
+
3
10
  [![npm version](https://img.shields.io/npm/v/@adtogether/web-sdk)](https://www.npmjs.com/package/@adtogether/web-sdk)
4
11
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
12
 
@@ -72,6 +72,34 @@ var AdTogether = class _AdTogether {
72
72
  static trackClick(adId, token) {
73
73
  this.trackEvent("/api/ads/click", adId, token);
74
74
  }
75
+ /**
76
+ * Detect the user's country code from the browser locale.
77
+ * Uses Intl API (most reliable) with navigator.language as fallback.
78
+ * Returns an ISO 3166-1 alpha-2 code like "US", "DE", "JP", or null.
79
+ */
80
+ static detectCountry() {
81
+ try {
82
+ if (typeof Intl !== "undefined" && Intl.DateTimeFormat) {
83
+ const resolved = Intl.DateTimeFormat().resolvedOptions();
84
+ if (resolved.locale) {
85
+ const parts = resolved.locale.split("-");
86
+ if (parts.length >= 2) {
87
+ const region = parts[parts.length - 1].toUpperCase();
88
+ if (region.length === 2) return region;
89
+ }
90
+ }
91
+ }
92
+ if (typeof navigator !== "undefined" && navigator.language) {
93
+ const parts = navigator.language.split("-");
94
+ if (parts.length >= 2) {
95
+ const region = parts[parts.length - 1].toUpperCase();
96
+ if (region.length === 2) return region;
97
+ }
98
+ }
99
+ } catch (_) {
100
+ }
101
+ return null;
102
+ }
75
103
  static trackEvent(endpoint, adId, token) {
76
104
  if (!_AdTogether.shared.assertInitialized()) return;
77
105
  fetch(`${_AdTogether.shared.baseUrl}${endpoint}`, {
@@ -86,7 +114,8 @@ var AdTogether = class _AdTogether {
86
114
  ..._AdTogether.shared.bundleId ? { bundleId: _AdTogether.shared.bundleId } : {},
87
115
  // Send platform and environment to match Flutter SDK
88
116
  platform: "web",
89
- environment: typeof process !== "undefined" && process.env?.NODE_ENV === "development" ? "development" : "production"
117
+ environment: typeof process !== "undefined" && process.env?.NODE_ENV === "development" ? "development" : "production",
118
+ country: _AdTogether.detectCountry()
90
119
  })
91
120
  }).catch(console.error);
92
121
  }
package/dist/index.d.mts CHANGED
@@ -31,6 +31,12 @@ declare class AdTogether {
31
31
  static fetchAd(adUnitId: string, adType?: AdType): Promise<AdModel>;
32
32
  static trackImpression(adId: string, token?: string): void;
33
33
  static trackClick(adId: string, token?: string): void;
34
+ /**
35
+ * Detect the user's country code from the browser locale.
36
+ * Uses Intl API (most reliable) with navigator.language as fallback.
37
+ * Returns an ISO 3166-1 alpha-2 code like "US", "DE", "JP", or null.
38
+ */
39
+ private static detectCountry;
34
40
  private static trackEvent;
35
41
  }
36
42
 
package/dist/index.d.ts CHANGED
@@ -31,6 +31,12 @@ declare class AdTogether {
31
31
  static fetchAd(adUnitId: string, adType?: AdType): Promise<AdModel>;
32
32
  static trackImpression(adId: string, token?: string): void;
33
33
  static trackClick(adId: string, token?: string): void;
34
+ /**
35
+ * Detect the user's country code from the browser locale.
36
+ * Uses Intl API (most reliable) with navigator.language as fallback.
37
+ * Returns an ISO 3166-1 alpha-2 code like "US", "DE", "JP", or null.
38
+ */
39
+ private static detectCountry;
34
40
  private static trackEvent;
35
41
  }
36
42
 
package/dist/index.js CHANGED
@@ -98,6 +98,34 @@ var AdTogether = class _AdTogether {
98
98
  static trackClick(adId, token) {
99
99
  this.trackEvent("/api/ads/click", adId, token);
100
100
  }
101
+ /**
102
+ * Detect the user's country code from the browser locale.
103
+ * Uses Intl API (most reliable) with navigator.language as fallback.
104
+ * Returns an ISO 3166-1 alpha-2 code like "US", "DE", "JP", or null.
105
+ */
106
+ static detectCountry() {
107
+ try {
108
+ if (typeof Intl !== "undefined" && Intl.DateTimeFormat) {
109
+ const resolved = Intl.DateTimeFormat().resolvedOptions();
110
+ if (resolved.locale) {
111
+ const parts = resolved.locale.split("-");
112
+ if (parts.length >= 2) {
113
+ const region = parts[parts.length - 1].toUpperCase();
114
+ if (region.length === 2) return region;
115
+ }
116
+ }
117
+ }
118
+ if (typeof navigator !== "undefined" && navigator.language) {
119
+ const parts = navigator.language.split("-");
120
+ if (parts.length >= 2) {
121
+ const region = parts[parts.length - 1].toUpperCase();
122
+ if (region.length === 2) return region;
123
+ }
124
+ }
125
+ } catch (_) {
126
+ }
127
+ return null;
128
+ }
101
129
  static trackEvent(endpoint, adId, token) {
102
130
  if (!_AdTogether.shared.assertInitialized()) return;
103
131
  fetch(`${_AdTogether.shared.baseUrl}${endpoint}`, {
@@ -112,7 +140,8 @@ var AdTogether = class _AdTogether {
112
140
  ..._AdTogether.shared.bundleId ? { bundleId: _AdTogether.shared.bundleId } : {},
113
141
  // Send platform and environment to match Flutter SDK
114
142
  platform: "web",
115
- environment: typeof process !== "undefined" && process.env?.NODE_ENV === "development" ? "development" : "production"
143
+ environment: typeof process !== "undefined" && process.env?.NODE_ENV === "development" ? "development" : "production",
144
+ country: _AdTogether.detectCountry()
116
145
  })
117
146
  }).catch(console.error);
118
147
  }
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  AdTogether
3
- } from "./chunk-RW43ES42.mjs";
3
+ } from "./chunk-IDISPRGA.mjs";
4
4
  export {
5
5
  AdTogether
6
6
  };
@@ -102,6 +102,34 @@ var AdTogether = class _AdTogether {
102
102
  static trackClick(adId, token) {
103
103
  this.trackEvent("/api/ads/click", adId, token);
104
104
  }
105
+ /**
106
+ * Detect the user's country code from the browser locale.
107
+ * Uses Intl API (most reliable) with navigator.language as fallback.
108
+ * Returns an ISO 3166-1 alpha-2 code like "US", "DE", "JP", or null.
109
+ */
110
+ static detectCountry() {
111
+ try {
112
+ if (typeof Intl !== "undefined" && Intl.DateTimeFormat) {
113
+ const resolved = Intl.DateTimeFormat().resolvedOptions();
114
+ if (resolved.locale) {
115
+ const parts = resolved.locale.split("-");
116
+ if (parts.length >= 2) {
117
+ const region = parts[parts.length - 1].toUpperCase();
118
+ if (region.length === 2) return region;
119
+ }
120
+ }
121
+ }
122
+ if (typeof navigator !== "undefined" && navigator.language) {
123
+ const parts = navigator.language.split("-");
124
+ if (parts.length >= 2) {
125
+ const region = parts[parts.length - 1].toUpperCase();
126
+ if (region.length === 2) return region;
127
+ }
128
+ }
129
+ } catch (_) {
130
+ }
131
+ return null;
132
+ }
105
133
  static trackEvent(endpoint, adId, token) {
106
134
  if (!_AdTogether.shared.assertInitialized()) return;
107
135
  fetch(`${_AdTogether.shared.baseUrl}${endpoint}`, {
@@ -116,7 +144,8 @@ var AdTogether = class _AdTogether {
116
144
  ..._AdTogether.shared.bundleId ? { bundleId: _AdTogether.shared.bundleId } : {},
117
145
  // Send platform and environment to match Flutter SDK
118
146
  platform: "web",
119
- environment: typeof process !== "undefined" && process.env?.NODE_ENV === "development" ? "development" : "production"
147
+ environment: typeof process !== "undefined" && process.env?.NODE_ENV === "development" ? "development" : "production",
148
+ country: _AdTogether.detectCountry()
120
149
  })
121
150
  }).catch(console.error);
122
151
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  AdTogether
3
- } from "../chunk-RW43ES42.mjs";
3
+ } from "../chunk-IDISPRGA.mjs";
4
4
 
5
5
  // src/react/AdTogetherBanner.tsx
6
6
  import { useEffect, useRef, useState } from "react";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adtogether/web-sdk",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
4
4
  "description": "The official AdTogether Web SDK — reciprocal ad exchange to increase conversions and grow your audience.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -95,6 +95,37 @@ export class AdTogether {
95
95
  this.trackEvent('/api/ads/click', adId, token);
96
96
  }
97
97
 
98
+ /**
99
+ * Detect the user's country code from the browser locale.
100
+ * Uses Intl API (most reliable) with navigator.language as fallback.
101
+ * Returns an ISO 3166-1 alpha-2 code like "US", "DE", "JP", or null.
102
+ */
103
+ private static detectCountry(): string | null {
104
+ try {
105
+ // Intl API gives the most reliable region
106
+ if (typeof Intl !== 'undefined' && Intl.DateTimeFormat) {
107
+ const resolved = Intl.DateTimeFormat().resolvedOptions();
108
+ // timeZone is like "America/New_York" — we can map it, but locale is simpler
109
+ if (resolved.locale) {
110
+ const parts = resolved.locale.split('-');
111
+ if (parts.length >= 2) {
112
+ const region = parts[parts.length - 1].toUpperCase();
113
+ if (region.length === 2) return region;
114
+ }
115
+ }
116
+ }
117
+ // Fallback: navigator.language (e.g. "en-US" -> "US")
118
+ if (typeof navigator !== 'undefined' && navigator.language) {
119
+ const parts = navigator.language.split('-');
120
+ if (parts.length >= 2) {
121
+ const region = parts[parts.length - 1].toUpperCase();
122
+ if (region.length === 2) return region;
123
+ }
124
+ }
125
+ } catch (_) {}
126
+ return null;
127
+ }
128
+
98
129
  private static trackEvent(endpoint: string, adId: string, token?: string) {
99
130
  if (!AdTogether.shared.assertInitialized()) return;
100
131
 
@@ -111,6 +142,7 @@ export class AdTogether {
111
142
  // Send platform and environment to match Flutter SDK
112
143
  platform: 'web',
113
144
  environment: typeof process !== 'undefined' && process.env?.NODE_ENV === 'development' ? 'development' : 'production',
145
+ country: AdTogether.detectCountry(),
114
146
  }),
115
147
  }).catch(console.error);
116
148
  }