@affiliateo/web 1.5.1 → 1.6.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,28 +1,2 @@
1
- /**
2
- * @affiliateo/web — Affiliate attribution and session tracking for web apps.
3
- *
4
- * React usage:
5
- * ```tsx
6
- * import { AffiliateoProvider } from '@affiliateo/web';
7
- *
8
- * export default function App() {
9
- * return (
10
- * <AffiliateoProvider campaignId="YOUR_CAMPAIGN_ID">
11
- * <YourApp />
12
- * </AffiliateoProvider>
13
- * );
14
- * }
15
- * ```
16
- *
17
- * Server-side (pass ref to Stripe checkout):
18
- * ```ts
19
- * import { getMetadata } from '@affiliateo/web';
20
- *
21
- * const session = await stripe.checkout.sessions.create({
22
- * metadata: getMetadata(req),
23
- * });
24
- * ```
25
- */
26
1
  export { AffiliateoProvider, useAffiliateRef } from './provider';
27
- export { getMetadata } from './metadata';
28
2
  export type { AffiliateoConfig, AffiliateoContextValue } from './types';
package/dist/index.js CHANGED
@@ -1,27 +1,2 @@
1
- /**
2
- * @affiliateo/web — Affiliate attribution and session tracking for web apps.
3
- *
4
- * React usage:
5
- * ```tsx
6
- * import { AffiliateoProvider } from '@affiliateo/web';
7
- *
8
- * export default function App() {
9
- * return (
10
- * <AffiliateoProvider campaignId="YOUR_CAMPAIGN_ID">
11
- * <YourApp />
12
- * </AffiliateoProvider>
13
- * );
14
- * }
15
- * ```
16
- *
17
- * Server-side (pass ref to Stripe checkout):
18
- * ```ts
19
- * import { getMetadata } from '@affiliateo/web';
20
- *
21
- * const session = await stripe.checkout.sessions.create({
22
- * metadata: getMetadata(req),
23
- * });
24
- * ```
25
- */
1
+ 'use client';
26
2
  export { AffiliateoProvider, useAffiliateRef } from './provider';
27
- export { getMetadata } from './metadata';
package/dist/provider.js CHANGED
@@ -14,7 +14,8 @@ function setCookie(name, value, days) {
14
14
  return;
15
15
  const dt = new Date();
16
16
  dt.setTime(dt.getTime() + days * 864e5);
17
- document.cookie = `${name}=${value};expires=${dt.toUTCString()};path=/;SameSite=Lax`;
17
+ const secure = window.location.protocol === 'https:' ? ';Secure' : '';
18
+ document.cookie = `${name}=${value};expires=${dt.toUTCString()};path=/;SameSite=Lax${secure}`;
18
19
  }
19
20
  // Generate UUID
20
21
  function uuid() {
@@ -52,17 +53,23 @@ export function AffiliateoProvider({ campaignId, apiUrl, children, }) {
52
53
  if (!vid) {
53
54
  vid = uuid();
54
55
  }
55
- setCookie('affiliateo_visitor_id', vid, 365);
56
- setCookie('affiliateo_campaign_id', campaignIdRef.current, 365);
56
+ setCookie('affiliateo_visitor_id', vid, 90);
57
+ setCookie('affiliateo_campaign_id', campaignIdRef.current, 90);
57
58
  // Read ref from URL params
58
59
  const params = new URLSearchParams(window.location.search);
59
60
  const ref = params.get('ref') || params.get('via') || params.get('source') || getCookie('affiliateo_ref') || null;
60
61
  if (ref) {
61
- setCookie('affiliateo_ref', ref, 365);
62
+ setCookie('affiliateo_ref', ref, 90);
62
63
  }
63
64
  setState({ refCode: ref, visitorId: vid });
65
+ // Throttle: max 1 pageview per second
66
+ let lastSendTime = 0;
64
67
  // Send pageview
65
68
  function sendPageview() {
69
+ const now = Date.now();
70
+ if (now - lastSendTime < 1000)
71
+ return;
72
+ lastSendTime = now;
66
73
  const payload = {
67
74
  type: 'pageview',
68
75
  campaign_id: campaignIdRef.current,
@@ -0,0 +1 @@
1
+ export { getMetadata } from './metadata';
package/dist/server.js ADDED
@@ -0,0 +1 @@
1
+ export { getMetadata } from './metadata';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@affiliateo/web",
3
- "version": "1.5.1",
3
+ "version": "1.6.0",
4
4
  "description": "Affiliateo web SDK — affiliate attribution and session tracking for web apps",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -10,6 +10,11 @@
10
10
  "types": "./dist/index.d.ts",
11
11
  "import": "./dist/index.js",
12
12
  "require": "./dist/index.js"
13
+ },
14
+ "./server": {
15
+ "types": "./dist/server.d.ts",
16
+ "import": "./dist/server.js",
17
+ "require": "./dist/server.js"
13
18
  }
14
19
  },
15
20
  "scripts": {