better-attribution
Advanced tools
Comparing version 1.0.1 to 1.0.2
declare const DefaultQueryParams: string[]; | ||
declare const betterAttribution: (opts?: { | ||
interface BetterAttribution { | ||
/** | ||
* A list of query params to store from the url | ||
* You can import {DefaultQueryParams} from 'better-attribution' if you'd like to add onto our list. | ||
* | ||
* @example [... DefaultQueryParams, 'utm_source', 'utm_medium', 'utm_campaign'] | ||
**/ | ||
queryParams?: string[]; | ||
/** | ||
* A prefix to add to the cookie keys. This is useful if you want to use this library multiple times. | ||
* The first and last touch keys will be prefixed with this value. | ||
* @example bobs_widgets becomes bobs_widgets_first_touch | ||
*/ | ||
cookiePrefix?: string; | ||
/** | ||
* The domain to set the cookie on. Defaults to the current domain. | ||
* @example .example.com | ||
**/ | ||
domain?: string; | ||
}) => { | ||
} | ||
declare const betterAttribution: (opts?: BetterAttribution) => { | ||
firstTouchKey: string; | ||
@@ -15,2 +31,2 @@ lastTouchKey: string; | ||
export { DefaultQueryParams, betterAttribution }; | ||
export { BetterAttribution, DefaultQueryParams, betterAttribution }; |
{ | ||
"name": "better-attribution", | ||
"version": "1.0.1", | ||
"description": "Track first and last attr", | ||
"version": "1.0.2", | ||
"description": "Allows you to easily tracks & store first/last touch attribution in cookies to enable multi-touch attribution. Tracks UTMs, Facebook, Google Ads, and more automatically.", | ||
"publishConfig": { | ||
@@ -11,2 +11,9 @@ "access": "public" | ||
], | ||
"keywords": [ | ||
"attribution", | ||
"first touch", | ||
"last touch", | ||
"utm tracking", | ||
"attribution cookie tracking" | ||
], | ||
"repository": { | ||
@@ -33,5 +40,5 @@ "type": "git", | ||
"@types/js-cookie": "^3.0.3", | ||
"prettier": "3.0.3", | ||
"tsup": "7.2.0", | ||
"typescript": "5.2.2", | ||
"prettier": "3.0.3", | ||
"vitest": "0.34.4" | ||
@@ -42,2 +49,2 @@ }, | ||
} | ||
} | ||
} |
@@ -10,23 +10,14 @@ # better-attribution | ||
const { storeAttributionValues, getLastTouch, getFirstTouch } = | ||
betterAttribution(); | ||
const attr = betterAttribution(); | ||
// Stores the current URL query params and referrer in a cross site cookie | ||
storeAttributionValues(); | ||
attr.storeAttributionValues(); | ||
// Retrieves an object of the query params and referrer from the latest visit | ||
const lastParams = getLastTouch(); | ||
// JSON from the latest visit | ||
const lastParams = attr.getLastTouch(); | ||
console.log(lastParams); // {referrer: 'facebook.com', fbclid: 'abc-123'} | ||
// Retrieves an object of the query params and referrer from the first visit | ||
const firstParams = getFirstTouch(); | ||
// optional arguments: | ||
betterAttribution({ | ||
// allows tracking of additional (or fewer) query params | ||
queryParams: [...DefaultQueryParams, "custom_known_query_param"], | ||
// allows prefixing the cookie w a custom string | ||
cookiePrefix: "custom_prefix", | ||
// allows setting the cookie w a custom domain | ||
domain: "example_2.com", | ||
}); | ||
// JSON from the first visit | ||
const firstParams = attr.getFirstTouch(); | ||
console.log(lastParams); // {utm_term: 'first-visit-term', referrer: 'google.com'} | ||
``` | ||
@@ -56,2 +47,16 @@ | ||
Customization: | ||
```js | ||
// All arguments are optional | ||
const attr = betterAttribution({ | ||
// allows tracking of additional (or fewer) query params | ||
queryParams: [...DefaultQueryParams, "custom_known_query_param"], | ||
// allows prefixing the cookie w a custom string | ||
cookiePrefix: "custom_prefix", | ||
// allows setting the cookie w a custom domain | ||
domain: "example_2.com", | ||
}); | ||
``` | ||
## Install | ||
@@ -58,0 +63,0 @@ |
Sorry, the diff of this file is not supported yet
13414
257
69