@adtogether/web-sdk 0.1.22 → 0.1.24
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 +7 -1
- package/README.md +8 -0
- package/dist/{chunk-RW43ES42.mjs → chunk-IDISPRGA.mjs} +30 -1
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +30 -1
- package/dist/index.mjs +1 -1
- package/dist/react/index.js +30 -1
- package/dist/react/index.mjs +1 -1
- package/package.json +1 -1
- package/src/core/AdTogether.ts +32 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
## 0.1.
|
|
1
|
+
## 0.1.24
|
|
2
|
+
* **Docs**: Standardized SDK documentation across all platforms.
|
|
3
|
+
|
|
4
|
+
## 0.1.23
|
|
2
5
|
|
|
6
|
+
* **Sync**: Version parity across all AdTogether SDKs.
|
|
7
|
+
|
|
8
|
+
## 0.1.22
|
|
3
9
|
* **Brand**: Added "Powered by AdTogether" attribution to all Interstitial ad formats.
|
|
4
10
|
* **Sync**: Unified versioning (0.1.20) across all AdTogether SDKs.
|
|
5
11
|
|
package/README.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# AdTogether Web SDK
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
<p align="center">
|
|
5
|
+
<img src="../../public/dashboard.png" width="800" alt="Developer Dashboard">
|
|
6
|
+
</p>
|
|
7
|
+
|
|
3
8
|
[](https://www.npmjs.com/package/@adtogether/web-sdk)
|
|
4
9
|
[](https://opensource.org/licenses/MIT)
|
|
5
10
|
|
|
@@ -14,6 +19,9 @@
|
|
|
14
19
|
|
|
15
20
|
This SDK allows web developers (React and Vanilla JS) to easily integrate AdTogether ads into their applications. By displaying ads from other community members, you earn **Ad Credits** that allow your own app's ads to be shown across the AdTogether network.
|
|
16
21
|
|
|
22
|
+
> [!IMPORTANT]
|
|
23
|
+
> **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`.
|
|
24
|
+
|
|
17
25
|
### 🖼️ Visualizing the Experience
|
|
18
26
|
|
|
19
27
|
| **Native Banner Ad** | **Interstitial Full-Screen** |
|
|
@@ -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
package/dist/react/index.js
CHANGED
|
@@ -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
|
}
|
package/dist/react/index.mjs
CHANGED
package/package.json
CHANGED
package/src/core/AdTogether.ts
CHANGED
|
@@ -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
|
}
|