@overlayed/ads 1.0.0 → 3.0.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/dist/index.d.ts CHANGED
@@ -1,5 +1,11 @@
1
+ //#region src/types.d.ts
2
+ type DivMapping = {
3
+ divId: string;
4
+ baseDivId: string;
5
+ targeting?: Record<string, string>;
6
+ };
7
+ //#endregion
1
8
  //#region src/utils.d.ts
2
-
3
9
  /**
4
10
  * Gets a new script element that when mounted, will load the ads script. You should append this to the document head.
5
11
  *
@@ -32,67 +38,35 @@ declare function getAdsScriptElement({
32
38
  */
33
39
  declare function getAdsScriptUrl(): string;
34
40
  //#endregion
35
- //#region src/reviq.d.ts
41
+ //#region src/aditude.d.ts
36
42
  /**
37
- * Sets a key-value pair for optional targeting
43
+ * Sets page-level targeting that is applied to subsequent ad requests.
38
44
  *
39
45
  * WARNING: You may not pass any user-identifiable data (including names, addresses, or user IDs) in targeting.
40
46
  *
41
- * @param key - The key to set.
42
- * @param value - The value to set.
47
+ * @param targeting - Key-value targeting pairs for the page.
43
48
  * @returns void
44
49
  */
45
- declare function setKv(key: string, value: string): void;
50
+ declare function setPageTargeting(targeting: Record<string, string>): void;
46
51
  /**
47
- * Sets multiple key-value pairs for optional targeting
48
- *
49
- * WARNING: You may not pass any user-identifiable data (including names, addresses, or user IDs) in targeting.
52
+ * Requests ads for the given div mappings. Call this on initial mount and whenever
53
+ * the page context changes (e.g. route navigation) to refresh ad fills.
50
54
  *
51
- * @param kvs - The key-value pairs to set.
52
- * @returns void
53
- */
54
- declare function setKvs(kvs: Record<string, string>): void;
55
- /**
56
- * Sets whether ads are enabled or not
57
- *
58
- * @param enabled - Whether ads are enabled or not.
59
- * @returns void
60
- */
61
- declare function setAdsEnabled(enabled: boolean): void;
62
- /**
63
- * Provide a user ID (uid) for targeting. Variadic.
64
- *
65
- * Providing a UID significantly improves ad performance. As such, it is optional, but highly recommended.
66
- *
67
- * We comply with all privacy regulations and do not store any user-identifiable data. Once passed to RevIQ, the UID is normalized and then hashed; we never store the original value.
68
- *
69
- * If the user has opted out of tracking, the UID will not be stored or transmitted. Thus it is safe to call this function regardless of the user’s tracking preferences.
70
- *
71
- * @param uid - The user ID to set.
72
- * @param uid.u - The username.
73
- * @param uid.e - The email.
74
- * @param uid.p - The phone.
75
- * @returns void
76
- */
77
- declare function setUid(uid: {
78
- u?: string;
79
- e?: string;
80
- p?: string;
81
- }): void;
82
- /**
83
- * Shows the consent dialog
55
+ * WARNING: You may not pass any user-identifiable data in per-mapping targeting.
84
56
  *
57
+ * @param mappings - Div mappings describing which ad slots to (re)fill and their targeting.
85
58
  * @returns void
86
59
  */
87
- declare function showConsent(): void;
60
+ declare function refreshAdsViaDivMappings(mappings: DivMapping[]): void;
88
61
  //#endregion
89
62
  //#region src/index.d.ts
90
63
  /**
91
64
  * Initializes the Overlayed Ads.
92
65
  * Overlayed must have been initialized on the electron side.
93
66
  *
94
- * This function only needs to be called once as it will retry initiailizing the ads until it succeeds.
67
+ * Sets the `app_id` page targeting. Safe to call before the ads script has loaded —
68
+ * the command is queued and drained once the provider is ready.
95
69
  */
96
70
  declare function init(): void;
97
71
  //#endregion
98
- export { getAdsScriptElement, getAdsScriptUrl, init, setAdsEnabled, setKv, setKvs, setUid, showConsent };
72
+ export { type DivMapping, getAdsScriptElement, getAdsScriptUrl, init, refreshAdsViaDivMappings, setPageTargeting };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- function e(e,...t){console.error(`[Overlayed] ${e}`,...t)}function t(e,...t){console.info(`[Overlayed] ${e}`,...t)}function n(e){globalThis.reviq=globalThis.reviq||[],globalThis.reviq.push(e)}function r(){return typeof window>`u`?!1:!(`__overlayed`in window)||!(`__overlayedRuntime`in window)||!window.__overlayed||!window.__overlayedRuntime?(e(`Could not find overlayed instance or runtime - did you import the preload script?`),!1):!0}function i({onError:e}){try{let t=a(),n=document.createElement(`script`);return n.type=`module`,n.src=t,n.onerror=n=>{e(n),console.error(`[Overlayed] Failed to load ads script: ${t}`,n)},n.onload=()=>{console.info(`[Overlayed] Ads script loaded successfully.`)},n}catch(e){console.error(`[Overlayed] Failed to create ads script element: ${e}`);return}}function a(){if(URL.canParse(window.__overlayed.application.siteUrl))return`//js.rev.iq/${new URL(window.__overlayed.application.siteUrl).hostname}`;throw Error(`Invalid site URL`)}function o(t,r){if(t===`app_id`){e(`[Overlayed] app_id is a reserved key`);return}n(e=>{e.setKv(t,r)})}function s(e,t){n(n=>{n.setKv(e,t)})}function c(t){if(t.app_id){e(`[Overlayed] app_id is a reserved key`);return}n(e=>{e.setKvs(t)})}function l(e){n(t=>{t.setAdsEnabled(e)})}function u(e){if(!r()||e.u){n(t=>{t.setUid(e)});return}n(t=>{t.setUid({...e,u:window.__overlayedRuntime?.userId})})}function d(){n(e=>{e.showConsent()})}function f(){if(typeof window>`u`)return;if(!window.__overlayed){e(`[Overlayed] Failed to initialize ads - could not find overlayed instance`);return}s(`app_id`,window.__overlayed.application.slug);let n=window.__overlayedRuntime?.userId;n===void 0?e(`[Overlayed] Could not find overlayed runtime - did you import the preload script?`):u({u:n}),t(`[Overlayed] Ads initialized!`)}export{i as getAdsScriptElement,a as getAdsScriptUrl,f as init,l as setAdsEnabled,o as setKv,c as setKvs,u as setUid,d as showConsent};
1
+ function e(e,...t){console.error(`[Overlayed] ${e}`,...t)}function t(e,...t){console.info(`[Overlayed] ${e}`,...t)}function n(e){globalThis.tude=globalThis.tude||{cmd:[]},globalThis.tude.cmd=globalThis.tude.cmd||[],globalThis.tude.cmd.push(()=>e(globalThis.tude))}function r({onError:e}){try{let t=i(),n=document.createElement(`script`);return n.async=!0,n.src=t,n.onerror=n=>{e(n),console.error(`[Overlayed] Failed to load ads script: ${t}`,n)},n.onload=()=>{console.info(`[Overlayed] Ads script loaded successfully.`)},n}catch(e){console.error(`[Overlayed] Failed to create ads script element: ${String(e)}`);return}}function i(){if(URL.canParse(window.__overlayed.application.siteUrl))return`https://htlbid.com/v3/${new URL(window.__overlayed.application.siteUrl).hostname}/htlbid.js`;throw Error(`Invalid site URL`)}function a(e){n(t=>{t.setPageTargeting(e)})}function o(e){n(t=>{t.refreshAdsViaDivMappings(e)})}function s(){if(!(typeof window>`u`)){if(!window.__overlayed){e(`Failed to initialize ads - could not find overlayed instance`);return}a({app_id:window.__overlayed.application.slug}),t(`Ads initialized!`)}}export{r as getAdsScriptElement,i as getAdsScriptUrl,s as init,o as refreshAdsViaDivMappings,a as setPageTargeting};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@overlayed/ads",
3
- "version": "1.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "Overlayed ads",
5
5
  "keywords": [
6
6
  "typescript"
@@ -30,11 +30,9 @@
30
30
  "access": "public"
31
31
  },
32
32
  "devDependencies": {
33
- "@ark/attest": "^0.49.0",
34
- "happy-dom": "^19.0.2",
35
- "tsdown": "0.18.1",
36
- "typescript": "^5.9.3",
37
- "vitest": "^3.2.4"
33
+ "@ark/attest": "^0.56.0",
34
+ "happy-dom": "^20.9.0",
35
+ "typescript": "^6.0.3"
38
36
  },
39
37
  "peerDependenciesMeta": {
40
38
  "typescript": {