utm-synapse
Version:
Track and report UTM parameters along a browser session
49 lines (48 loc) • 1.94 kB
TypeScript
export declare enum UtmParamEnum {
Source = "utm_source",
Medium = "utm_medium",
Campaign = "utm_campaign",
Content = "utm_content",
Name = "utm_name",
Term = "utm_term",
InitialSource = "initial_utm_source",
InitialMedium = "initial_utm_medium",
InitialCampaign = "initial_utm_campaign",
InitialContent = "initial_utm_content",
InitialName = "initial_utm_name",
InitialTerm = "initial_utm_term",
Gclid = "gclid"
}
export type UtmParams = Partial<Record<UtmParamEnum, string>>;
/** Its instance allows you to deal with UTM parameters */
export declare class UtmSynapse {
static readonly StorageKey: string;
protected readonly storage: Storage | null;
constructor();
/** Extract UTM parameters from a URL or by default `window.location.href` */
parse(url?: string): UtmParams | null;
/** Save UTM parameters for later usage */
save(params: UtmParams): void;
/** Load any UTM parameter in the storage */
load(): UtmParams | null;
/** Clear the storage of any UTM parameter */
clear(): void;
/** Remove UTM parameters from an URL */
trimUrl(url: string): string;
/**
* Will ask the browser to remove UTM parameters without reloading the page.
* Can be useful to avoid users doing copy/paste with UTM parameters
*
* Tip: you should save parameters before doing this (because they would be lost otherwise)
* Note: if the history browser feature is not accessible it won't work
*/
cleanDisplayedUrl(): void;
/**
* Will add provided parameters to the URL
*
* Note: in case the URL already contains one of those parameters already, we remove all the original ones before patching (to not mix different analytics sessions)
*/
setIntoUrl(url: string, params: UtmParams): string;
}
/** Default global instance for the ease of use */
export declare const utmSynapse: UtmSynapse;