swetrix 2.3.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc.js +13 -0
- package/dist/esnext/Lib.d.ts +42 -13
- package/dist/esnext/Lib.js +49 -80
- package/dist/esnext/Lib.js.map +1 -1
- package/dist/esnext/index.d.ts +10 -0
- package/dist/esnext/index.js +15 -1
- package/dist/esnext/index.js.map +1 -1
- package/dist/esnext/utils.d.ts +20 -1
- package/dist/esnext/utils.js +27 -3
- package/dist/esnext/utils.js.map +1 -1
- package/dist/swetrix.cjs.js +94 -88
- package/dist/swetrix.es5.js +94 -89
- package/dist/swetrix.js +1 -1
- package/dist/swetrix.orig.js +94 -88
- package/package.json +5 -5
- package/src/Lib.ts +110 -99
- package/src/index.ts +16 -3
- package/src/utils.ts +35 -3
package/src/utils.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
interface IGetPath {
|
|
2
|
+
hash?: boolean
|
|
3
|
+
search?: boolean
|
|
4
|
+
}
|
|
5
|
+
|
|
1
6
|
const findInSearch = (exp: RegExp): string | undefined => {
|
|
2
7
|
const res = location.search.match(exp)
|
|
3
8
|
return (res && res[2]) || undefined
|
|
@@ -41,7 +46,34 @@ export const getUTMMedium = () => findInSearch(utmMediumRegex)
|
|
|
41
46
|
|
|
42
47
|
export const getUTMCampaign = () => findInSearch(utmCampaignRegex)
|
|
43
48
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Function used to track the current page (path) of the application.
|
|
51
|
+
* Will work in cases where the path looks like:
|
|
52
|
+
* - /path
|
|
53
|
+
* - /#/path
|
|
54
|
+
* - /path?search
|
|
55
|
+
* - /path?search#hash
|
|
56
|
+
* - /path#hash?search
|
|
57
|
+
*
|
|
58
|
+
* @param options - Options for the function.
|
|
59
|
+
* @param options.hash - Whether to trigger on hash change.
|
|
60
|
+
* @param options.search - Whether to trigger on search change.
|
|
61
|
+
* @returns The path of the current page.
|
|
62
|
+
*/
|
|
63
|
+
export const getPath = (options: IGetPath): string => {
|
|
64
|
+
let result = location.pathname || ''
|
|
65
|
+
|
|
66
|
+
if (options.hash) {
|
|
67
|
+
const hashIndex = location.hash.indexOf('?')
|
|
68
|
+
const hashString = hashIndex > -1 ? location.hash.substring(0, hashIndex) : location.hash
|
|
69
|
+
result += hashString
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (options.search) {
|
|
73
|
+
const hashIndex = location.hash.indexOf('?')
|
|
74
|
+
const searchString = location.search || (hashIndex > -1 ? location.hash.substring(hashIndex) : '')
|
|
75
|
+
result += searchString
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return result
|
|
47
79
|
}
|