better-attribution
Advanced tools
Comparing version
@@ -1,3 +0,3 @@ | ||
declare const DefaultQueryParams: string[]; | ||
interface BetterAttribution { | ||
declare const DefaultQueryParams: readonly ["utm_source", "utm_medium", "utm_campaign", "utm_content", "utm_name", "utm_term", "fbclid", "ad_id", "gclid", "gc_id"]; | ||
interface BetterAttribution<T extends readonly string[]> { | ||
/** | ||
@@ -9,3 +9,3 @@ * A list of query params to store from the url | ||
**/ | ||
queryParams?: string[]; | ||
queryParams?: T; | ||
/** | ||
@@ -23,7 +23,7 @@ * A prefix to add to the cookie keys. This is useful if you want to use this library multiple times. | ||
} | ||
declare const betterAttribution: (opts?: BetterAttribution) => { | ||
declare const betterAttribution: <T extends readonly string[] = readonly ["utm_source", "utm_medium", "utm_campaign", "utm_content", "utm_name", "utm_term", "fbclid", "ad_id", "gclid", "gc_id"]>(opts?: BetterAttribution<T> | undefined) => { | ||
firstTouchKey: string; | ||
lastTouchKey: string; | ||
getLastTouch: () => Record<string, string>; | ||
getFirstTouch: () => Record<string, string>; | ||
getLastTouch: () => Record<T[number], string | undefined>; | ||
getFirstTouch: () => Record<T[number], string | undefined>; | ||
getCurrentParams: () => Record<string, string>; | ||
@@ -30,0 +30,0 @@ storeAttributionValues: () => void; |
@@ -45,13 +45,2 @@ "use strict"; | ||
// src/prefixObject.ts | ||
var prefixObject = (prefix, obj) => { | ||
return Object.entries(obj).reduce( | ||
(acc, [key, val]) => { | ||
acc[`${prefix}${key}`] = val; | ||
return acc; | ||
}, | ||
{} | ||
); | ||
}; | ||
// src/index.ts | ||
@@ -84,3 +73,3 @@ var DefaultQueryParams = [ | ||
const object = f ? JSON.parse(f) : {}; | ||
return prefixObject("first_", object); | ||
return object; | ||
}; | ||
@@ -90,3 +79,3 @@ const getLastTouch = () => { | ||
const object = l ? JSON.parse(l) : {}; | ||
return prefixObject("last_", object); | ||
return object; | ||
}; | ||
@@ -93,0 +82,0 @@ const getCurrentParams = () => { |
{ | ||
"name": "better-attribution", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"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.", | ||
@@ -32,2 +32,3 @@ "publishConfig": { | ||
"build": "yarn run build-fast -- --dts-resolve", | ||
"test": "vitest", | ||
"lint": "prettier --write .", | ||
@@ -40,2 +41,3 @@ "prepublishOnly": "yarn run build", | ||
"@types/js-cookie": "^3.0.3", | ||
"jsdom": "^22.1.0", | ||
"prettier": "3.0.3", | ||
@@ -49,2 +51,2 @@ "tsup": "7.2.0", | ||
} | ||
} | ||
} |
@@ -21,3 +21,3 @@ # better-attribution | ||
const firstParams = attr.getFirstTouch(); | ||
console.log(lastParams); // {utm_term: 'first-visit-term', referrer: 'google.com'} | ||
console.log(firstParams); // {utm_term: 'first-visit-term', referrer: 'google.com'} | ||
``` | ||
@@ -53,3 +53,3 @@ | ||
// allows tracking of additional (or fewer) query params | ||
queryParams: [...DefaultQueryParams, "custom_known_query_param"], | ||
queryParams: [...DefaultQueryParams, "custom_known_query_param"] as const, | ||
// allows prefixing the cookie w a custom string | ||
@@ -60,2 +60,3 @@ cookiePrefix: "custom_prefix", | ||
}); | ||
attr.getFirstTouch().custom_known_query_param // undefined | string | ||
``` | ||
@@ -62,0 +63,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
13737
2.41%70
1.45%6
20%237
-7.78%