@dub/analytics
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -1,16 +0,74 @@ | ||
type AllowedPropertyValues = string | number | boolean | null; | ||
interface AnalyticsProps { | ||
apiKey?: string; | ||
trackEndpoint?: string; | ||
affiliateParamKey?: string; | ||
cookieOptions?: { | ||
/** | ||
* Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.3|Domain Set-Cookie attribute}. By default, no | ||
* domain is set, and most clients will consider the cookie to apply to only | ||
* the current domain. | ||
*/ | ||
domain?: string | undefined; | ||
/** | ||
* Specifies the `Date` object to be the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.1|`Expires` `Set-Cookie` attribute}. By default, | ||
* no expiration is set, and most clients will consider this a "non-persistent cookie" and will delete | ||
* it on a condition like exiting a web browser application. | ||
* | ||
* *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification} | ||
* states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is | ||
* possible not all clients by obey this, so if both are set, they should | ||
* point to the same date and time. | ||
*/ | ||
expires?: Date | undefined; | ||
/** | ||
* Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.6|`HttpOnly` `Set-Cookie` attribute}. | ||
* When truthy, the `HttpOnly` attribute is set, otherwise it is not. By | ||
* default, the `HttpOnly` attribute is not set. | ||
* | ||
* *Note* be careful when setting this to true, as compliant clients will | ||
* not allow client-side JavaScript to see the cookie in `document.cookie`. | ||
*/ | ||
httpOnly?: boolean | undefined; | ||
/** | ||
* Specifies the number (in seconds) to be the value for the `Max-Age` | ||
* `Set-Cookie` attribute. The given number will be converted to an integer | ||
* by rounding down. By default, no maximum age is set. | ||
* | ||
* *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification} | ||
* states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is | ||
* possible not all clients by obey this, so if both are set, they should | ||
* point to the same date and time. | ||
*/ | ||
maxAge?: number | undefined; | ||
/** | ||
* Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.4|`Path` `Set-Cookie` attribute}. | ||
* By default, the path is considered the "default path". | ||
*/ | ||
path?: string | undefined; | ||
/** | ||
* Specifies the boolean or string to be the value for the {@link https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7|`SameSite` `Set-Cookie` attribute}. | ||
* | ||
* - `true` will set the `SameSite` attribute to `Strict` for strict same | ||
* site enforcement. | ||
* - `false` will not set the `SameSite` attribute. | ||
* - `'lax'` will set the `SameSite` attribute to Lax for lax same site | ||
* enforcement. | ||
* - `'strict'` will set the `SameSite` attribute to Strict for strict same | ||
* site enforcement. | ||
* - `'none'` will set the SameSite attribute to None for an explicit | ||
* cross-site cookie. | ||
* | ||
* More information about the different enforcement levels can be found in {@link https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7|the specification}. | ||
* | ||
* *note* This is an attribute that has not yet been fully standardized, and may change in the future. This also means many clients may ignore this attribute until they understand it. | ||
*/ | ||
sameSite?: true | false | 'lax' | 'strict' | 'none' | undefined; | ||
/** | ||
* Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.5|`Secure` `Set-Cookie` attribute}. When truthy, the | ||
* `Secure` attribute is set, otherwise it is not. By default, the `Secure` attribute is not set. | ||
* | ||
* *Note* be careful when setting this to `true`, as compliant clients will | ||
* not send the cookie back to the server in the future if the browser does | ||
* not have an HTTPS connection. | ||
*/ | ||
secure?: boolean | undefined; | ||
}; | ||
} | ||
type TrackEventProperties = Record<string, AllowedPropertyValues>; | ||
declare global { | ||
interface Window { | ||
da?: { | ||
trackClick: (url: string) => void; | ||
trackConversion: (eventName: string, properties?: TrackEventProperties) => void; | ||
}; | ||
} | ||
} | ||
@@ -20,3 +78,3 @@ /** | ||
*/ | ||
declare function inject(): void; | ||
declare function inject(props: AnalyticsProps): void; | ||
@@ -23,0 +81,0 @@ declare const _default: { |
// package.json | ||
var version = "0.0.5"; | ||
var name = "@dub/analytics"; | ||
var version = "0.0.6"; | ||
@@ -13,3 +14,3 @@ // src/utils.tsx | ||
// src/generic.ts | ||
function inject() { | ||
function inject(props) { | ||
if (!isBrowser()) | ||
@@ -23,3 +24,8 @@ return; | ||
script.defer = true; | ||
script.setAttribute("data-sdkn", name); | ||
script.setAttribute("data-sdkv", version); | ||
script.setAttribute( | ||
"data-cookie-options", | ||
JSON.stringify(props.cookieOptions) | ||
); | ||
script.onerror = () => { | ||
@@ -26,0 +32,0 @@ console.log(`[Dub Web Analytics] failed to load script from ${src}.`); |
@@ -1,16 +0,74 @@ | ||
type AllowedPropertyValues = string | number | boolean | null; | ||
interface AnalyticsProps { | ||
apiKey?: string; | ||
trackEndpoint?: string; | ||
affiliateParamKey?: string; | ||
cookieOptions?: { | ||
/** | ||
* Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.3|Domain Set-Cookie attribute}. By default, no | ||
* domain is set, and most clients will consider the cookie to apply to only | ||
* the current domain. | ||
*/ | ||
domain?: string | undefined; | ||
/** | ||
* Specifies the `Date` object to be the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.1|`Expires` `Set-Cookie` attribute}. By default, | ||
* no expiration is set, and most clients will consider this a "non-persistent cookie" and will delete | ||
* it on a condition like exiting a web browser application. | ||
* | ||
* *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification} | ||
* states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is | ||
* possible not all clients by obey this, so if both are set, they should | ||
* point to the same date and time. | ||
*/ | ||
expires?: Date | undefined; | ||
/** | ||
* Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.6|`HttpOnly` `Set-Cookie` attribute}. | ||
* When truthy, the `HttpOnly` attribute is set, otherwise it is not. By | ||
* default, the `HttpOnly` attribute is not set. | ||
* | ||
* *Note* be careful when setting this to true, as compliant clients will | ||
* not allow client-side JavaScript to see the cookie in `document.cookie`. | ||
*/ | ||
httpOnly?: boolean | undefined; | ||
/** | ||
* Specifies the number (in seconds) to be the value for the `Max-Age` | ||
* `Set-Cookie` attribute. The given number will be converted to an integer | ||
* by rounding down. By default, no maximum age is set. | ||
* | ||
* *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification} | ||
* states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is | ||
* possible not all clients by obey this, so if both are set, they should | ||
* point to the same date and time. | ||
*/ | ||
maxAge?: number | undefined; | ||
/** | ||
* Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.4|`Path` `Set-Cookie` attribute}. | ||
* By default, the path is considered the "default path". | ||
*/ | ||
path?: string | undefined; | ||
/** | ||
* Specifies the boolean or string to be the value for the {@link https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7|`SameSite` `Set-Cookie` attribute}. | ||
* | ||
* - `true` will set the `SameSite` attribute to `Strict` for strict same | ||
* site enforcement. | ||
* - `false` will not set the `SameSite` attribute. | ||
* - `'lax'` will set the `SameSite` attribute to Lax for lax same site | ||
* enforcement. | ||
* - `'strict'` will set the `SameSite` attribute to Strict for strict same | ||
* site enforcement. | ||
* - `'none'` will set the SameSite attribute to None for an explicit | ||
* cross-site cookie. | ||
* | ||
* More information about the different enforcement levels can be found in {@link https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7|the specification}. | ||
* | ||
* *note* This is an attribute that has not yet been fully standardized, and may change in the future. This also means many clients may ignore this attribute until they understand it. | ||
*/ | ||
sameSite?: true | false | 'lax' | 'strict' | 'none' | undefined; | ||
/** | ||
* Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.5|`Secure` `Set-Cookie` attribute}. When truthy, the | ||
* `Secure` attribute is set, otherwise it is not. By default, the `Secure` attribute is not set. | ||
* | ||
* *Note* be careful when setting this to `true`, as compliant clients will | ||
* not send the cookie back to the server in the future if the browser does | ||
* not have an HTTPS connection. | ||
*/ | ||
secure?: boolean | undefined; | ||
}; | ||
} | ||
type TrackEventProperties = Record<string, AllowedPropertyValues>; | ||
declare global { | ||
interface Window { | ||
da?: { | ||
trackClick: (url: string) => void; | ||
trackConversion: (eventName: string, properties?: TrackEventProperties) => void; | ||
}; | ||
} | ||
} | ||
@@ -33,4 +91,4 @@ /** | ||
*/ | ||
declare function Analytics(): null; | ||
declare function Analytics(props: AnalyticsProps): null; | ||
export { Analytics, AnalyticsProps }; |
@@ -7,3 +7,4 @@ "use client"; | ||
// package.json | ||
var version = "0.0.5"; | ||
var name = "@dub/analytics"; | ||
var version = "0.0.6"; | ||
@@ -19,3 +20,3 @@ // src/utils.tsx | ||
// src/generic.ts | ||
function inject() { | ||
function inject(props) { | ||
if (!isBrowser()) | ||
@@ -29,3 +30,8 @@ return; | ||
script.defer = true; | ||
script.setAttribute("data-sdkn", name); | ||
script.setAttribute("data-sdkv", version); | ||
script.setAttribute( | ||
"data-cookie-options", | ||
JSON.stringify(props.cookieOptions) | ||
); | ||
script.onerror = () => { | ||
@@ -38,6 +44,6 @@ console.log(`[Dub Web Analytics] failed to load script from ${src}.`); | ||
// src/react.tsx | ||
function Analytics() { | ||
function Analytics(props) { | ||
useEffect(() => { | ||
inject(); | ||
}, []); | ||
inject(props); | ||
}, [props]); | ||
return null; | ||
@@ -44,0 +50,0 @@ } |
{ | ||
"name": "@dub/analytics", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -1,2 +0,2 @@ | ||
import { version } from '../package.json'; | ||
import { name, version } from '../package.json'; | ||
import type { AnalyticsProps } from './types'; | ||
@@ -8,3 +8,3 @@ import { getScriptSrc, isBrowser } from './utils'; | ||
*/ | ||
function inject(): void { | ||
function inject(props: AnalyticsProps): void { | ||
if (!isBrowser()) return; | ||
@@ -19,3 +19,8 @@ | ||
script.defer = true; | ||
script.setAttribute('data-sdkn', name); | ||
script.setAttribute('data-sdkv', version); | ||
script.setAttribute( | ||
'data-cookie-options', | ||
JSON.stringify(props.cookieOptions), | ||
); | ||
@@ -22,0 +27,0 @@ script.onerror = (): void => { |
105
src/types.ts
export type AllowedPropertyValues = string | number | boolean | null; | ||
export interface ClickApiResponse { | ||
clickId: string; | ||
} | ||
export interface AnalyticsProps { | ||
apiKey?: string; | ||
trackEndpoint?: string; | ||
affiliateParamKey?: string; | ||
} | ||
cookieOptions?: { | ||
/** | ||
* Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.3|Domain Set-Cookie attribute}. By default, no | ||
* domain is set, and most clients will consider the cookie to apply to only | ||
* the current domain. | ||
*/ | ||
domain?: string | undefined; | ||
export type TrackEventProperties = Record<string, AllowedPropertyValues>; | ||
export type SaleEventProperties = TrackEventProperties & { | ||
value: number; | ||
currency: string; | ||
}; | ||
export interface TrackFunction { | ||
(eventName: string, properties?: TrackEventProperties): void; | ||
signUp: (properties: TrackEventProperties) => void; | ||
purchase: ( | ||
properties: TrackEventProperties & { value: number; currency: string }, | ||
) => void; | ||
/** | ||
* Specifies the `Date` object to be the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.1|`Expires` `Set-Cookie` attribute}. By default, | ||
* no expiration is set, and most clients will consider this a "non-persistent cookie" and will delete | ||
* it on a condition like exiting a web browser application. | ||
* | ||
* *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification} | ||
* states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is | ||
* possible not all clients by obey this, so if both are set, they should | ||
* point to the same date and time. | ||
*/ | ||
expires?: Date | undefined; | ||
/** | ||
* Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.6|`HttpOnly` `Set-Cookie` attribute}. | ||
* When truthy, the `HttpOnly` attribute is set, otherwise it is not. By | ||
* default, the `HttpOnly` attribute is not set. | ||
* | ||
* *Note* be careful when setting this to true, as compliant clients will | ||
* not allow client-side JavaScript to see the cookie in `document.cookie`. | ||
*/ | ||
httpOnly?: boolean | undefined; | ||
/** | ||
* Specifies the number (in seconds) to be the value for the `Max-Age` | ||
* `Set-Cookie` attribute. The given number will be converted to an integer | ||
* by rounding down. By default, no maximum age is set. | ||
* | ||
* *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification} | ||
* states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is | ||
* possible not all clients by obey this, so if both are set, they should | ||
* point to the same date and time. | ||
*/ | ||
maxAge?: number | undefined; | ||
/** | ||
* Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.4|`Path` `Set-Cookie` attribute}. | ||
* By default, the path is considered the "default path". | ||
*/ | ||
path?: string | undefined; | ||
/** | ||
* Specifies the boolean or string to be the value for the {@link https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7|`SameSite` `Set-Cookie` attribute}. | ||
* | ||
* - `true` will set the `SameSite` attribute to `Strict` for strict same | ||
* site enforcement. | ||
* - `false` will not set the `SameSite` attribute. | ||
* - `'lax'` will set the `SameSite` attribute to Lax for lax same site | ||
* enforcement. | ||
* - `'strict'` will set the `SameSite` attribute to Strict for strict same | ||
* site enforcement. | ||
* - `'none'` will set the SameSite attribute to None for an explicit | ||
* cross-site cookie. | ||
* | ||
* More information about the different enforcement levels can be found in {@link https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7|the specification}. | ||
* | ||
* *note* This is an attribute that has not yet been fully standardized, and may change in the future. This also means many clients may ignore this attribute until they understand it. | ||
*/ | ||
sameSite?: true | false | 'lax' | 'strict' | 'none' | undefined; | ||
/** | ||
* Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.5|`Secure` `Set-Cookie` attribute}. When truthy, the | ||
* `Secure` attribute is set, otherwise it is not. By default, the `Secure` attribute is not set. | ||
* | ||
* *Note* be careful when setting this to `true`, as compliant clients will | ||
* not send the cookie back to the server in the future if the browser does | ||
* not have an HTTPS connection. | ||
*/ | ||
secure?: boolean | undefined; | ||
}; | ||
} | ||
declare global { | ||
interface Window { | ||
// Base interface | ||
da?: { | ||
trackClick: (url: string) => void; | ||
trackConversion: ( | ||
eventName: string, | ||
properties?: TrackEventProperties, | ||
) => void; | ||
}; | ||
} | ||
export interface ClickApiResponse { | ||
clickId: string; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
62285
646
0