Skip to content

Commit 268f6ce

Browse files
Paul Boocockpaulboocock
authored andcommitted
Add documentation to @snowplow/browser-tracker (close snowplow#939)
1 parent 784282d commit 268f6ce

141 files changed

Lines changed: 2700 additions & 356 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
- name: Upload plugins
8282
uses: actions/upload-artifact@v2
8383
with:
84-
name: plugins-umd
84+
name: plugins.umd
8585
path: |
8686
./plugins/*/dist/*.umd.js
8787
./plugins/*/dist/*.umd.js.map

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ common/deploy/
6363
common/temp/
6464
common/autoinstallers/*/.npmrc
6565
**/.rush/temp/
66+
trackers/browser-tracker/temp/
6667

6768
# Distribution files
6869
dist

libraries/browser-tracker-core/src/helpers.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export interface FilterCriterion<T> {
4848

4949
/**
5050
* Checks if an object is a string
51-
* @param str The object to check
51+
* @param str - The object to check
5252
*/
5353
export function isString(str: Object): str is string {
5454
if (str && typeof str.valueOf() === 'string') {
@@ -59,7 +59,7 @@ export function isString(str: Object): str is string {
5959

6060
/**
6161
* Checks if an object is an integer
62-
* @param int The object to check
62+
* @param int - The object to check
6363
*/
6464
export function isInteger(int: Object): int is number {
6565
return (
@@ -69,7 +69,7 @@ export function isInteger(int: Object): int is number {
6969

7070
/**
7171
* Checks if the input parameter is a function
72-
* @param func The object to check
72+
* @param func - The object to check
7373
*/
7474
export function isFunction(func: unknown) {
7575
if (func && typeof func === 'function') {
@@ -127,7 +127,7 @@ export function fixupDomain(domain: string) {
127127
* in the old URL. It will be returned unless overriden
128128
* by a "refer(r)er" parameter in the querystring.
129129
*
130-
* @param string oldLocation Optional.
130+
* @param string - oldLocation Optional.
131131
* @return string The referrer
132132
*/
133133
export function getReferrer(oldLocation?: string) {
@@ -198,9 +198,9 @@ export function fromQuerystring(field: string, url: string) {
198198
/**
199199
* Add a name-value pair to the querystring of a URL
200200
*
201-
* @param string url URL to decorate
202-
* @param string name Name of the querystring pair
203-
* @param string value Value of the querystring pair
201+
* @param string - url URL to decorate
202+
* @param string - name Name of the querystring pair
203+
* @param string - value Value of the querystring pair
204204
*/
205205
export function decorateQuerystring(url: string, name: string, value: string) {
206206
var initialQsParams = name + '=' + value;
@@ -234,7 +234,7 @@ export function decorateQuerystring(url: string, name: string, value: string) {
234234
/**
235235
* Attempt to get a value from localStorage
236236
*
237-
* @param string key
237+
* @param string - key
238238
* @return string The value obtained from localStorage, or
239239
* undefined if localStorage is inaccessible
240240
*/
@@ -257,9 +257,9 @@ export function attemptGetLocalStorage(key: string) {
257257
/**
258258
* Attempt to write a value to localStorage
259259
*
260-
* @param string key
261-
* @param string value
262-
* @param number ttl Time to live in seconds, defaults to 2 years from Date.now()
260+
* @param string - key
261+
* @param string - value
262+
* @param number - ttl Time to live in seconds, defaults to 2 years from Date.now()
263263
* @return boolean Whether the operation succeeded
264264
*/
265265
export function attemptWriteLocalStorage(key: string, value: string, ttl = 63072000) {
@@ -277,7 +277,7 @@ export function attemptWriteLocalStorage(key: string, value: string, ttl = 63072
277277
/**
278278
* Attempt to delete a value from localStorage
279279
*
280-
* @param string key
280+
* @param string - key
281281
* @return boolean Whether the operation succeeded
282282
*/
283283
export function attemptDeleteLocalStorage(key: string) {
@@ -294,7 +294,7 @@ export function attemptDeleteLocalStorage(key: string) {
294294
/**
295295
* Attempt to get a value from sessionStorage
296296
*
297-
* @param string key
297+
* @param string - key
298298
* @return string The value obtained from sessionStorage, or
299299
* undefined if sessionStorage is inaccessible
300300
*/
@@ -309,8 +309,8 @@ export function attemptGetSessionStorage(key: string) {
309309
/**
310310
* Attempt to write a value to sessionStorage
311311
*
312-
* @param string key
313-
* @param string value
312+
* @param string - key
313+
* @param string - value
314314
* @return boolean Whether the operation succeeded
315315
*/
316316
export function attemptWriteSessionStorage(key: string, value: string) {
@@ -356,8 +356,8 @@ export function findRootDomain(sameSite: string, secure: boolean) {
356356
/**
357357
* Checks whether a value is present within an array
358358
*
359-
* @param val The value to check for
360-
* @param array The array to check within
359+
* @param val - The value to check for
360+
* @param array - The array to check within
361361
* @return boolean Whether it exists
362362
*/
363363
export function isValueInArray<T>(val: T, array: T[]) {
@@ -372,8 +372,8 @@ export function isValueInArray<T>(val: T, array: T[]) {
372372
/**
373373
* Deletes an arbitrary cookie by setting the expiration date to the past
374374
*
375-
* @param cookieName The name of the cookie to delete
376-
* @param domainName The domain the cookie is in
375+
* @param cookieName - The name of the cookie to delete
376+
* @param domainName - The domain the cookie is in
377377
*/
378378
export function deleteCookie(cookieName: string, domainName?: string, sameSite?: string, secure?: boolean) {
379379
cookie(cookieName, '', -1, '/', domainName, sameSite, secure);
@@ -382,7 +382,7 @@ export function deleteCookie(cookieName: string, domainName?: string, sameSite?:
382382
/**
383383
* Fetches the name of all cookies beginning with a certain prefix
384384
*
385-
* @param cookiePrefix The prefix to check for
385+
* @param cookiePrefix - The prefix to check for
386386
* @return array The cookies that begin with the prefix
387387
*/
388388
export function getCookiesWithPrefix(cookiePrefix: string) {
@@ -400,13 +400,13 @@ export function getCookiesWithPrefix(cookiePrefix: string) {
400400
* Get and set the cookies associated with the current document in browser
401401
* This implementation always returns a string, returns the cookie value if only name is specified
402402
*
403-
* @param name The cookie name (required)
404-
* @param value The cookie value
405-
* @param ttl The cookie Time To Live (seconds)
406-
* @param path The cookies path
407-
* @param domain The cookies domain
408-
* @param samesite The cookies samesite attribute
409-
* @param secure Boolean to specify if cookie should be secure
403+
* @param name - The cookie name (required)
404+
* @param value - The cookie value
405+
* @param ttl - The cookie Time To Live (seconds)
406+
* @param path - The cookies path
407+
* @param domain - The cookies domain
408+
* @param samesite - The cookies samesite attribute
409+
* @param secure - Boolean to specify if cookie should be secure
410410
* @return string The cookies value
411411
*/
412412
export function cookie(
@@ -437,7 +437,7 @@ export function cookie(
437437
* Parses an object and returns either the
438438
* integer or undefined.
439439
*
440-
* @param obj The object to parse
440+
* @param obj - The object to parse
441441
* @return the result of the parse operation
442442
*/
443443
export function parseAndValidateInt(obj: unknown) {
@@ -449,7 +449,7 @@ export function parseAndValidateInt(obj: unknown) {
449449
* Parses an object and returns either the
450450
* number or undefined.
451451
*
452-
* @param obj The object to parse
452+
* @param obj - The object to parse
453453
* @return the result of the parse operation
454454
*/
455455
export function parseAndValidateFloat(obj: unknown) {
@@ -460,10 +460,10 @@ export function parseAndValidateFloat(obj: unknown) {
460460
/**
461461
* Convert a criterion object to a filter function
462462
*
463-
* @param object criterion Either {allowlist: [array of allowable strings]}
463+
* @param object - criterion Either {allowlist: [array of allowable strings]}
464464
* or {denylist: [array of allowable strings]}
465465
* or {filter: function (elt) {return whether to track the element}
466-
* @param boolean byClass Whether to allowlist/denylist based on an element's classes (for forms)
466+
* @param boolean - byClass Whether to allowlist/denylist based on an element's classes (for forms)
467467
* or name attribute (for fields)
468468
*/
469469
export function getFilterByClass(criterion?: FilterCriterion<HTMLElement> | null): (elt: HTMLElement) => boolean {
@@ -485,7 +485,7 @@ export function getFilterByClass(criterion?: FilterCriterion<HTMLElement> | null
485485
/**
486486
* Convert a criterion object to a filter function
487487
*
488-
* @param object criterion Either {allowlist: [array of allowable strings]}
488+
* @param object - criterion Either {allowlist: [array of allowable strings]}
489489
* or {denylist: [array of allowable strings]}
490490
* or {filter: function (elt) {return whether to track the element}
491491
*/

libraries/browser-tracker-core/src/snowplow.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ const namedTrackers: Record<string, BrowserTracker> = {};
3838
/**
3939
* Dispatch function to all specified trackers
4040
*
41-
* @param trackers An optional list of trackers to send the event to, or will send to all trackers
42-
* @param fn The function which will run against each tracker
41+
* @param trackers - An optional list of trackers to send the event to, or will send to all trackers
42+
* @param fn - The function which will run against each tracker
4343
*/
4444
export function dispatchToTrackers(trackers: Array<string> | undefined, fn: (t: BrowserTracker) => void) {
4545
try {
@@ -52,9 +52,9 @@ export function dispatchToTrackers(trackers: Array<string> | undefined, fn: (t:
5252
/**
5353
* Dispatch function to all specified trackers from the supplied collection
5454
*
55-
* @param trackers An optional list of trackers to send the event to, or will send to all trackers
56-
* @param trackerCollection The collection which the trackers will be selected from
57-
* @param fn The function which will run against each tracker
55+
* @param trackers - An optional list of trackers to send the event to, or will send to all trackers
56+
* @param trackerCollection - The collection which the trackers will be selected from
57+
* @param fn - The function which will run against each tracker
5858
*/
5959
export function dispatchToTrackersInCollection(
6060
trackers: Array<string> | undefined,
@@ -70,20 +70,20 @@ export function dispatchToTrackersInCollection(
7070

7171
/**
7272
* Checks if a tracker has been created for a particular identifier
73-
* @param trackerId The unique identifier of the tracker
73+
* @param trackerId - The unique identifier of the tracker
7474
*/
7575
export function trackerExists(trackerId: string) {
7676
return namedTrackers.hasOwnProperty(trackerId);
7777
}
7878

7979
/**
8080
* Creates a Tracker and adds it to the internal collection
81-
* @param trackerId The unique identifier of the tracker
82-
* @param namespace The namespace of the tracker, tracked with each event as `tna`
83-
* @param version The current version of the tracker library
84-
* @param endpoint The endpoint to send events to
85-
* @param sharedState The instance of shared state to use for this tracker
86-
* @param configuration The configuration to use for this tracker instance
81+
* @param trackerId - The unique identifier of the tracker
82+
* @param namespace - The namespace of the tracker, tracked with each event as `tna`
83+
* @param version - The current version of the tracker library
84+
* @param endpoint - The endpoint to send events to
85+
* @param sharedState - The instance of shared state to use for this tracker
86+
* @param configuration - The configuration to use for this tracker instance
8787
*/
8888
export function addTracker(
8989
trackerId: string,
@@ -102,7 +102,7 @@ export function addTracker(
102102

103103
/**
104104
* Gets a single instance of the internal tracker object
105-
* @param trackerId The unique identifier of the tracker
105+
* @param trackerId - The unique identifier of the tracker
106106
* @returns The tracker instance, or null if not found
107107
*/
108108
export function getTracker(trackerId: string) {
@@ -116,7 +116,7 @@ export function getTracker(trackerId: string) {
116116

117117
/**
118118
* Gets an array of tracker instances based on the list of identifiers
119-
* @param trackerIds An array of unique identifiers of the trackers
119+
* @param trackerIds - An array of unique identifiers of the trackers
120120
* @returns The tracker instances, or empty list if none found
121121
*/
122122
export function getTrackers(trackerIds: Array<string>): Array<BrowserTracker> {

libraries/browser-tracker-core/src/tracker/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ type ActivityTrackingConfig = {
106106
/**
107107
* The Snowplow Tracker
108108
*
109-
* @param trackerId The unique identifier of the tracker
110-
* @param namespace The namespace of the tracker object
111-
* @param version The current version of the JavaScript Tracker
112-
* @param endpoint The collector endpoint to send events to, with or without protocol
113-
* @param sharedState An object containing state which is shared across tracker instances
114-
* @param trackerConfiguration Dictionary of configuration options
109+
* @param trackerId - The unique identifier of the tracker
110+
* @param namespace - The namespace of the tracker object
111+
* @param version - The current version of the JavaScript Tracker
112+
* @param endpoint - The collector endpoint to send events to, with or without protocol
113+
* @param sharedState - An object containing state which is shared across tracker instances
114+
* @param trackerConfiguration - Dictionary of configuration options
115115
*/
116116
export function Tracker(
117117
trackerId: string,
@@ -319,7 +319,7 @@ export function Tracker(
319319
/**
320320
* Decorate the querystring of a single link
321321
*
322-
* @param event e The event targeting the link
322+
* @param event - e The event targeting the link
323323
*/
324324
function linkDecorationHandler(evt: Event) {
325325
var timestamp = new Date().getTime();
@@ -334,7 +334,7 @@ export function Tracker(
334334
* Whenever such a link is clicked on or navigated to via the keyboard,
335335
* add "_sp={{duid}}.{{timestamp}}" to its querystring
336336
*
337-
* @param crossDomainLinker Function used to determine which links to decorate
337+
* @param crossDomainLinker - Function used to determine which links to decorate
338338
*/
339339
function decorateLinks(crossDomainLinker: (elt: HTMLAnchorElement | HTMLAreaElement) => boolean) {
340340
for (var i = 0; i < document.links.length; i++) {
@@ -751,7 +751,7 @@ export function Tracker(
751751
/**
752752
* Adds the protocol in front of our collector URL
753753
*
754-
* @param string collectorUrl The collector URL with or without protocol
754+
* @param string - collectorUrl The collector URL with or without protocol
755755
* @returns string collectorUrl The tracker URL with protocol
756756
*/
757757
function asCollectorUrl(collectorUrl: string) {
@@ -853,8 +853,8 @@ export function Tracker(
853853
/**
854854
* Combine an array of unchanging contexts with the result of a context-creating function
855855
*
856-
* @param staticContexts Array of custom contexts
857-
* @param contextCallback Function returning an array of contexts
856+
* @param staticContexts - Array of custom contexts
857+
* @param contextCallback - Function returning an array of contexts
858858
*/
859859
function finalizeContexts(
860860
staticContexts?: Array<SelfDescribingJson> | null,

0 commit comments

Comments
 (0)