@shware/analytics 8.3.0 → 8.6.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.
Files changed (100) hide show
  1. package/README.md +28 -16
  2. package/dist/hooks/use-uet-id-sync.cjs +19 -0
  3. package/dist/hooks/use-uet-id-sync.cjs.map +1 -0
  4. package/dist/hooks/use-uet-id-sync.d.cts +10 -0
  5. package/dist/hooks/use-uet-id-sync.d.cts.map +1 -0
  6. package/dist/hooks/use-uet-id-sync.d.mts +10 -0
  7. package/dist/hooks/use-uet-id-sync.d.mts.map +1 -0
  8. package/dist/hooks/use-uet-id-sync.mjs +18 -0
  9. package/dist/hooks/use-uet-id-sync.mjs.map +1 -0
  10. package/dist/hooks/use-web-analytics.cjs +11 -5
  11. package/dist/hooks/use-web-analytics.cjs.map +1 -1
  12. package/dist/hooks/use-web-analytics.d.cts +4 -1
  13. package/dist/hooks/use-web-analytics.d.cts.map +1 -1
  14. package/dist/hooks/use-web-analytics.d.mts +4 -1
  15. package/dist/hooks/use-web-analytics.d.mts.map +1 -1
  16. package/dist/hooks/use-web-analytics.mjs +11 -5
  17. package/dist/hooks/use-web-analytics.mjs.map +1 -1
  18. package/dist/next/index.cjs +40 -2
  19. package/dist/next/index.cjs.map +1 -1
  20. package/dist/next/index.d.cts +5 -1
  21. package/dist/next/index.d.cts.map +1 -1
  22. package/dist/next/index.d.mts +5 -1
  23. package/dist/next/index.d.mts.map +1 -1
  24. package/dist/next/index.mjs +41 -3
  25. package/dist/next/index.mjs.map +1 -1
  26. package/dist/react-router/index.cjs +27 -3
  27. package/dist/react-router/index.cjs.map +1 -1
  28. package/dist/react-router/index.d.cts +5 -1
  29. package/dist/react-router/index.d.cts.map +1 -1
  30. package/dist/react-router/index.d.mts +5 -1
  31. package/dist/react-router/index.d.mts.map +1 -1
  32. package/dist/react-router/index.mjs +27 -3
  33. package/dist/react-router/index.mjs.map +1 -1
  34. package/dist/schema/index.cjs +1 -0
  35. package/dist/schema/index.cjs.map +1 -1
  36. package/dist/schema/index.d.cts +4 -0
  37. package/dist/schema/index.d.cts.map +1 -1
  38. package/dist/schema/index.d.mts +4 -0
  39. package/dist/schema/index.d.mts.map +1 -1
  40. package/dist/schema/index.mjs +1 -0
  41. package/dist/schema/index.mjs.map +1 -1
  42. package/dist/server/index.d.cts +2 -2
  43. package/dist/server/index.d.mts +2 -2
  44. package/dist/server/microsoft-conversions-api.cjs +8 -8
  45. package/dist/server/microsoft-conversions-api.cjs.map +1 -1
  46. package/dist/server/microsoft-conversions-api.d.cts +15 -8
  47. package/dist/server/microsoft-conversions-api.d.cts.map +1 -1
  48. package/dist/server/microsoft-conversions-api.d.mts +15 -8
  49. package/dist/server/microsoft-conversions-api.d.mts.map +1 -1
  50. package/dist/server/microsoft-conversions-api.mjs +8 -8
  51. package/dist/server/microsoft-conversions-api.mjs.map +1 -1
  52. package/dist/server/openai-conversions-api.cjs +1 -1
  53. package/dist/server/openai-conversions-api.mjs +1 -1
  54. package/dist/server/reddit-conversions-api.cjs +1 -1
  55. package/dist/server/reddit-conversions-api.mjs +1 -1
  56. package/dist/tanstack/analytics.cjs +27 -3
  57. package/dist/tanstack/analytics.cjs.map +1 -1
  58. package/dist/tanstack/analytics.d.cts +5 -1
  59. package/dist/tanstack/analytics.d.cts.map +1 -1
  60. package/dist/tanstack/analytics.d.mts +5 -1
  61. package/dist/tanstack/analytics.d.mts.map +1 -1
  62. package/dist/tanstack/analytics.mjs +27 -3
  63. package/dist/tanstack/analytics.mjs.map +1 -1
  64. package/dist/third-parties/index.cjs +3 -1
  65. package/dist/third-parties/index.d.cts +2 -2
  66. package/dist/third-parties/index.d.mts +2 -2
  67. package/dist/third-parties/index.mjs +2 -2
  68. package/dist/third-parties/meta-pixel.cjs +1 -1
  69. package/dist/third-parties/meta-pixel.mjs +1 -1
  70. package/dist/third-parties/microsoft-uet.cjs +45 -17
  71. package/dist/third-parties/microsoft-uet.cjs.map +1 -1
  72. package/dist/third-parties/microsoft-uet.d.cts +13 -19
  73. package/dist/third-parties/microsoft-uet.d.cts.map +1 -1
  74. package/dist/third-parties/microsoft-uet.d.mts +13 -19
  75. package/dist/third-parties/microsoft-uet.d.mts.map +1 -1
  76. package/dist/third-parties/microsoft-uet.mjs +44 -18
  77. package/dist/third-parties/microsoft-uet.mjs.map +1 -1
  78. package/dist/third-parties/openai-pixel.cjs +1 -1
  79. package/dist/third-parties/openai-pixel.mjs +1 -1
  80. package/dist/third-parties/reddit-pixel.cjs +1 -1
  81. package/dist/third-parties/reddit-pixel.mjs +1 -1
  82. package/dist/track/types.d.cts +7 -0
  83. package/dist/track/types.d.cts.map +1 -1
  84. package/dist/track/types.d.mts +7 -0
  85. package/dist/track/types.d.mts.map +1 -1
  86. package/dist/web/index.cjs +25 -1
  87. package/dist/web/index.cjs.map +1 -1
  88. package/dist/web/index.d.cts.map +1 -1
  89. package/dist/web/index.d.mts.map +1 -1
  90. package/dist/web/index.mjs +25 -1
  91. package/dist/web/index.mjs.map +1 -1
  92. package/dist/web/page-key.cjs +53 -0
  93. package/dist/web/page-key.cjs.map +1 -0
  94. package/dist/web/page-key.d.cts +24 -0
  95. package/dist/web/page-key.d.cts.map +1 -0
  96. package/dist/web/page-key.d.mts +24 -0
  97. package/dist/web/page-key.d.mts.map +1 -0
  98. package/dist/web/page-key.mjs +52 -0
  99. package/dist/web/page-key.mjs.map +1 -0
  100. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","names":[],"sources":["../../src/track/types.ts"],"mappings":";;KAEY;KACA,YAAY;KAEZ,UAAU,UAAU,YAAY,aAAa,gBAAgB,iBACrE,IACA;;;;;;;;;;;;;;;;;;;;;;;;;;;UA+Ba;;;;;;;KAQZ,oBAAoB,KAAK,gBAAgB,wBAC1C,sBAAsB;KAGd,gBAAgB,UAAU,YAAY,aAAa,gBAAgB,iBAC3E,eAAe,KAAK,oBAAoB,KACxC,gBAAgB,wBACd,sBAAsB,KACtB,OAAO,mBAAmB;KAEpB;KACA;UAEK;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe,yBAAyB;EACxC;EACA;EACA;EACA;EACA;IAAa;IAAc;IAAe;;EAE1C;EACA;;KAGU,qBAAqB,UAAU,WACzC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;;EAEf;EACA;;UAGe;EACf;EACA;EACA;;;;;;;;;;UAWe;EACf;EACA;EACA;;;;;;EAMA;;UAGe;;;;;;;EAOf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;EACA;EACA;EACA;;EAEA;EACA;;EAEA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;;;;UAQe;;EAEf;;;;;;;;;;;;EAqCA;;;;;;EAuDA;;EAMA;;EAEA;;EAEA;;EAEA;;EAUA;;EAEA;;UAGe,kBACP,cAAc,YAAY,SAAS,iBAAiB,UAAU,iBAAiB;EACvF;GACC;;UAGc,WAAW,UAAU,YAAY;EAChD;EACA,MAAM,UAAU;EAChB,MAAM;EACN;EACA;EACA,UAAU;EACV,aAAa;EACb,aAAa,gBAAgB;EAC7B;;KAGU;;EAEV"}
1
+ {"version":3,"file":"types.d.cts","names":[],"sources":["../../src/track/types.ts"],"mappings":";;KAEY;KACA,YAAY;KAEZ,UAAU,UAAU,YAAY,aAAa,gBAAgB,iBACrE,IACA;;;;;;;;;;;;;;;;;;;;;;;;;;;UA+Ba;;;;;;;KAQZ,oBAAoB,KAAK,gBAAgB,wBAC1C,sBAAsB;KAGd,gBAAgB,UAAU,YAAY,aAAa,gBAAgB,iBAC3E,eAAe,KAAK,oBAAoB,KACxC,gBAAgB,wBACd,sBAAsB,KACtB,OAAO,mBAAmB;KAEpB;KACA;UAEK;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe,yBAAyB;EACxC;EACA;EACA;EACA;EACA;IAAa;IAAc;IAAe;;EAE1C;EACA;;KAGU,qBAAqB,UAAU,WACzC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;;EAEf;EACA;;UAGe;EACf;EACA;EACA;;;;;;;;;;UAWe;EACf;EACA;EACA;;;;;;;EAOA;;;;;;EAMA;;UAGe;;;;;;;EAOf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;EACA;EACA;EACA;;EAEA;EACA;;EAEA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;;;;UAQe;;EAEf;;;;;;;;;;;;EAqCA;;;;;;EAuDA;;EAMA;;EAEA;;EAEA;;EAEA;;EAUA;;EAEA;;UAGe,kBACP,cAAc,YAAY,SAAS,iBAAiB,UAAU,iBAAiB;EACvF;GACC;;UAGc,WAAW,UAAU,YAAY;EAChD;EACA,MAAM,UAAU;EAChB,MAAM;EACN;EACA;EACA,UAAU;EACV,aAAa;EACb,aAAa,gBAAgB;EAC7B;;KAGU;;EAEV"}
@@ -108,6 +108,13 @@ interface PageInfo {
108
108
  page_location?: string;
109
109
  page_referrer?: string;
110
110
  page_title?: string;
111
+ /**
112
+ * Identifies one page load: every event of a page carries the same id, and a navigation — a
113
+ * reload, or a single-page-app route change, the same moments a `page_view` is sent — starts
114
+ * a new one. Lets a server-side sender tie a conversion to the page load it happened on
115
+ * (Microsoft's `pageLoadId`). Web only.
116
+ */
117
+ page_load_id?: string;
111
118
  /**
112
119
  * @deprecated Renamed to `page_location` in 7.0.0, and never set by this SDK any more.
113
120
  * Declared so events from clients still on an older version keep their page URL through
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","names":[],"sources":["../../src/track/types.ts"],"mappings":";;KAEY;KACA,YAAY;KAEZ,UAAU,UAAU,YAAY,aAAa,gBAAgB,iBACrE,IACA;;;;;;;;;;;;;;;;;;;;;;;;;;;UA+Ba;;;;;;;KAQZ,oBAAoB,KAAK,gBAAgB,wBAC1C,sBAAsB;KAGd,gBAAgB,UAAU,YAAY,aAAa,gBAAgB,iBAC3E,eAAe,KAAK,oBAAoB,KACxC,gBAAgB,wBACd,sBAAsB,KACtB,OAAO,mBAAmB;KAEpB;KACA;UAEK;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe,yBAAyB;EACxC;EACA;EACA;EACA;EACA;IAAa;IAAc;IAAe;;EAE1C;EACA;;KAGU,qBAAqB,UAAU,WACzC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;;EAEf;EACA;;UAGe;EACf;EACA;EACA;;;;;;;;;;UAWe;EACf;EACA;EACA;;;;;;EAMA;;UAGe;;;;;;;EAOf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;EACA;EACA;EACA;;EAEA;EACA;;EAEA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;;;;UAQe;;EAEf;;;;;;;;;;;;EAqCA;;;;;;EAuDA;;EAMA;;EAEA;;EAEA;;EAEA;;EAUA;;EAEA;;UAGe,kBACP,cAAc,YAAY,SAAS,iBAAiB,UAAU,iBAAiB;EACvF;GACC;;UAGc,WAAW,UAAU,YAAY;EAChD;EACA,MAAM,UAAU;EAChB,MAAM;EACN;EACA;EACA,UAAU;EACV,aAAa;EACb,aAAa,gBAAgB;EAC7B;;KAGU;;EAEV"}
1
+ {"version":3,"file":"types.d.mts","names":[],"sources":["../../src/track/types.ts"],"mappings":";;KAEY;KACA,YAAY;KAEZ,UAAU,UAAU,YAAY,aAAa,gBAAgB,iBACrE,IACA;;;;;;;;;;;;;;;;;;;;;;;;;;;UA+Ba;;;;;;;KAQZ,oBAAoB,KAAK,gBAAgB,wBAC1C,sBAAsB;KAGd,gBAAgB,UAAU,YAAY,aAAa,gBAAgB,iBAC3E,eAAe,KAAK,oBAAoB,KACxC,gBAAgB,wBACd,sBAAsB,KACtB,OAAO,mBAAmB;KAEpB;KACA;UAEK;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe,yBAAyB;EACxC;EACA;EACA;EACA;EACA;IAAa;IAAc;IAAe;;EAE1C;EACA;;KAGU,qBAAqB,UAAU,WACzC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;;EAEf;EACA;;UAGe;EACf;EACA;EACA;;;;;;;;;;UAWe;EACf;EACA;EACA;;;;;;;EAOA;;;;;;EAMA;;UAGe;;;;;;;EAOf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;EACA;EACA;EACA;;EAEA;EACA;;EAEA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;;;;UAQe;;EAEf;;;;;;;;;;;;EAqCA;;;;;;EAuDA;;EAMA;;EAEA;;EAEA;;EAEA;;EAUA;;EAEA;;UAGe,kBACP,cAAc,YAAY,SAAS,iBAAiB,UAAU,iBAAiB;EACvF;GACC;;UAGc,WAAW,UAAU,YAAY;EAChD;EACA,MAAM,UAAU;EAChB,MAAM;EACN;EACA;EACA,UAAU;EACV,aAAa;EACb,aAAa,gBAAgB;EAC7B;;KAGU;;EAEV"}
@@ -4,18 +4,40 @@ const require_setup_index = require("../setup/index.cjs");
4
4
  const require_constants_storage = require("../constants/storage.cjs");
5
5
  const require_link_index = require("../link/index.cjs");
6
6
  const require_click_id_index = require("../click-id/index.cjs");
7
+ const require_web_page_key = require("./page-key.cjs");
7
8
  const require_es5$1 = require("../node_modules/.pnpm/bowser@2.14.1/node_modules/bowser/es5.cjs");
8
9
  let uuid = require("uuid");
9
10
  let cookie = require("cookie");
10
11
  //#region src/web/index.ts
11
12
  var import_es5 = /* @__PURE__ */ require_runtime.__toESM(require_es5$1.default, 1);
13
+ function randomUUID() {
14
+ return crypto.randomUUID ? crypto.randomUUID() : (0, uuid.v4)();
15
+ }
12
16
  function getDeviceId() {
13
17
  const cached = require_setup_index.config.storage.getItem(require_constants_storage.keys.device_id);
14
18
  if (cached) return cached;
15
- const id = crypto.randomUUID ? crypto.randomUUID() : (0, uuid.v4)();
19
+ const id = randomUUID();
16
20
  require_setup_index.config.storage.setItem(require_constants_storage.keys.device_id, id);
17
21
  return id;
18
22
  }
23
+ /**
24
+ * The current page load, keyed by the page it was loaded at. A module variable and nothing more
25
+ * persistent: the id must die with the page (a reload is a new page load, and storage would
26
+ * carry it over — or, shared across tabs, let two pages overwrite each other's).
27
+ *
28
+ * Keyed by `getPageKey` because that is what the SDK's own `page_view` fires on (see
29
+ * `useWebAnalytics`): the id exists to link an event to the `page_view` of the page it happened
30
+ * on, so it must rotate exactly when a `page_view` is sent — path or query change, yes; hash
31
+ * change or tracking-parameter cleanup, no.
32
+ */
33
+ let pageLoad;
34
+ function getPageLoadId(page) {
35
+ if (pageLoad?.page !== page) pageLoad = {
36
+ page,
37
+ id: randomUUID()
38
+ };
39
+ return pageLoad.id;
40
+ }
19
41
  const links = /* @__PURE__ */ new Map();
20
42
  /**
21
43
  * `getTags` runs once per event now, and the link a `?s=` id points at cannot change while the
@@ -36,6 +58,7 @@ function getCachedLink(id) {
36
58
  let parser;
37
59
  async function getTags() {
38
60
  const page_location = window.location.href;
61
+ const page_load_id = getPageLoadId(require_web_page_key.getPageKey(window.location.pathname, window.location.search));
39
62
  const page_referrer = document.referrer || void 0;
40
63
  const page_title = document.title;
41
64
  parser ??= import_es5.default.getParser(window.navigator.userAgent);
@@ -67,6 +90,7 @@ async function getTags() {
67
90
  page_location,
68
91
  page_referrer,
69
92
  page_title,
93
+ page_load_id,
70
94
  fbc: parsed._fbc ?? void 0,
71
95
  fbp: parsed._fbp,
72
96
  fbclid: params.get("fbclid") ?? void 0,
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["config","keys","uuidv4","getLink","Bowser","parseCookie","parseGcl","parseUetMsclkid"],"sources":["../../src/web/index.ts"],"sourcesContent":["import Bowser from 'bowser';\nimport { parseCookie } from 'cookie';\nimport { v4 as uuidv4 } from 'uuid';\nimport { parseGcl, parseUetMsclkid } from '../click-id/index';\nimport { keys } from '../constants/storage';\nimport { type Link, getLink } from '../link/index';\nimport { type Storage, cache, config } from '../setup/index';\nimport type { TrackTags } from '../track/types';\n\nexport function getDeviceId() {\n const cached = config.storage.getItem(keys.device_id);\n if (cached) return cached;\n // lib.dom types `crypto.randomUUID` as always present, but it is missing in\n // insecure contexts and older browsers, so probe it before use.\n const id = (crypto as Partial<Crypto>).randomUUID ? crypto.randomUUID() : uuidv4();\n config.storage.setItem(keys.device_id, id);\n return id;\n}\n\nconst links = new Map<string, Promise<Link | null>>();\n\n/**\n * `getTags` runs once per event now, and the link a `?s=` id points at cannot change while the\n * page is open, so an uncached lookup would put an identical request on the wire for every\n * event the page sends.\n */\nfunction getCachedLink(id: string) {\n const cached = links.get(id);\n if (cached) return cached;\n const link = getLink(id).then((result) => {\n // A lookup that came back empty must not stick for the lifetime of the page. `getLink`\n // answers null for a network failure as well as for a link that does not exist, and losing\n // the link's utm params for every later event costs more than repeating a rare request.\n if (!result) links.delete(id);\n return result;\n });\n links.set(id, link);\n return link;\n}\n\n/** The user agent cannot change while the page is open, so it is parsed once. */\nlet parser: ReturnType<typeof Bowser.getParser> | undefined;\n\nexport async function getTags() {\n // Read the page before the first await: `getTags` runs when the event happens, and a single\n // page app can navigate while the link lookup below is still in flight.\n const page_location = window.location.href;\n const page_referrer = document.referrer || undefined;\n const page_title = document.title;\n\n parser ??= Bowser.getParser(window.navigator.userAgent);\n const params = new URLSearchParams(window.location.search);\n const os = parser.getOS();\n const browser = parser.getBrowser();\n const platform = parser.getPlatform();\n const parsed = parseCookie(document.cookie);\n\n const linkId = params.get('s');\n const link = linkId ? await getCachedLink(linkId) : null;\n\n const tags: TrackTags = {\n os: `${os.name} ${os.version}`,\n os_name: os.name,\n os_version: os.version,\n browser: `${browser.name} ${browser.version}`,\n browser_name: browser.name,\n browser_version: browser.version,\n device: platform.model,\n device_id: getDeviceId(),\n device_type: platform.type,\n device_vendor: platform.vendor,\n device_pixel_ratio: window.devicePixelRatio,\n screen_width: window.screen.width,\n screen_height: window.screen.height,\n screen_resolution: `${window.screen.width}x${window.screen.height}`,\n release: config.release,\n language: navigator.language,\n time_zone: Intl.DateTimeFormat().resolvedOptions().timeZone,\n page_location,\n page_referrer,\n page_title,\n // Meta Ads — _fbc is set server-side (see @shware/analytics/server resolveClickIdCookies)\n fbc: parsed._fbc ?? undefined,\n fbp: parsed._fbp,\n fbclid: params.get('fbclid') ?? undefined,\n ad_id: params.get('ad_id') ?? undefined,\n ad_name: params.get('ad_name') ?? undefined,\n adset_id: params.get('adset_id') ?? undefined,\n adset_name: params.get('adset_name') ?? undefined,\n campaign_id: params.get('campaign_id') ?? undefined,\n campaign_name: params.get('campaign_name') ?? undefined,\n placement: params.get('placement') ?? undefined,\n site_source_name: params.get('site_source_name') ?? undefined,\n // Google Ads — _gcl_aw/_gcl_gb are written by gtag and kept alive server-side (see\n // @shware/analytics/server resolveClickIdCookies); the URL wins, the cookie carries the\n // click id to every later page of the visit and to returning visits.\n gclid: params.get('gclid') ?? parseGcl(parsed._gcl_aw)?.clickId,\n gclsrc: params.get('gclsrc') ?? undefined,\n gad_source: params.get('gad_source') ?? undefined,\n gad_campaignid: params.get('gad_campaignid') ?? undefined,\n // Reddit Ads — _rdt_cid is set server-side (see @shware/analytics/server resolveClickIdCookies)\n rdt_cid: params.get('rdt_cid') ?? parsed._rdt_cid ?? undefined,\n rdt_uuid: parsed._rdt_uuid,\n // LinkedIn Ads: get click id from url params or first-party cookie\n li_fat_id: params.get('li_fat_id') ?? parsed.li_fat_id ?? undefined,\n // click ids\n dclid: params.get('dclid') ?? undefined,\n ko_click_id: params.get('ko_click_id') ?? undefined,\n // Microsoft Ads — _uetmsclkid is written by the UET tag and kept alive server-side (see\n // @shware/analytics/server resolveClickIdCookies); the URL wins, the cookie carries the\n // click id to every later page of the visit and to returning visits.\n msclkid: params.get('msclkid') ?? parseUetMsclkid(parsed._uetmsclkid),\n sccid: params.get('sccid') ?? undefined,\n ttclid: params.get('ttclid') ?? undefined,\n twclid: params.get('twclid') ?? undefined,\n wbraid: params.get('wbraid') ?? parseGcl(parsed._gcl_gb)?.clickId,\n gbraid: params.get('gbraid') ?? undefined,\n yclid: params.get('yclid') ?? undefined,\n // utm params\n utm_source: link?.utm_source ?? params.get('utm_source') ?? undefined,\n utm_medium: link?.utm_medium ?? params.get('utm_medium') ?? undefined,\n utm_campaign: link?.utm_campaign ?? params.get('utm_campaign') ?? undefined,\n utm_term: link?.utm_term ?? params.get('utm_term') ?? undefined,\n utm_content: link?.utm_content ?? params.get('utm_content') ?? undefined,\n utm_id: link?.utm_id ?? params.get('utm_id') ?? undefined,\n utm_source_platform:\n link?.utm_source_platform ?? params.get('utm_source_platform') ?? undefined,\n utm_creative_format:\n link?.utm_creative_format ?? params.get('utm_creative_format') ?? undefined,\n utm_marketing_tactic:\n link?.utm_marketing_tactic ?? params.get('utm_marketing_tactic') ?? undefined,\n };\n\n cache.tags = tags;\n return tags;\n}\n\nconst map = new Map<string, string>();\n\nexport const storage: Storage = {\n getItem: (key) => {\n try {\n return localStorage.getItem(key);\n } catch {\n console.error('localStorage is not available');\n return map.get(key) ?? null;\n }\n },\n setItem: (key, value) => {\n try {\n localStorage.setItem(key, value);\n } catch {\n console.error('localStorage is not available');\n map.set(key, value);\n }\n },\n};\n"],"mappings":";;;;;;;;;;;AASA,SAAgB,cAAc;CAC5B,MAAM,SAASA,oBAAAA,OAAO,QAAQ,QAAQC,0BAAAA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sclkid"],"sources":["../../src/web/index.ts"],"sourcesContent":["import Bowser from 'bowser';\nimport { parseCookie } from 'cookie';\nimport { v4 as uuidv4 } from 'uuid';\nimport { parseGcl, parseUetMsclkid } from '../click-id/index';\nimport { keys } from '../constants/storage';\nimport { type Link, getLink } from '../link/index';\nimport { type Storage, cache, config } from '../setup/index';\nimport type { TrackTags } from '../track/types';\nimport { getPageKey } from './page-key';\n\n// lib.dom types `crypto.randomUUID` as always present, but it is missing in insecure contexts\n// and older browsers, so probe it before use.\nfunction randomUUID(): string {\n return (crypto as Partial<Crypto>).randomUUID ? crypto.randomUUID() : uuidv4();\n}\n\nexport function getDeviceId() {\n const cached = config.storage.getItem(keys.device_id);\n if (cached) return cached;\n const id = randomUUID();\n config.storage.setItem(keys.device_id, id);\n return id;\n}\n\n/**\n * The current page load, keyed by the page it was loaded at. A module variable and nothing more\n * persistent: the id must die with the page (a reload is a new page load, and storage would\n * carry it over — or, shared across tabs, let two pages overwrite each other's).\n *\n * Keyed by `getPageKey` because that is what the SDK's own `page_view` fires on (see\n * `useWebAnalytics`): the id exists to link an event to the `page_view` of the page it happened\n * on, so it must rotate exactly when a `page_view` is sent — path or query change, yes; hash\n * change or tracking-parameter cleanup, no.\n */\nlet pageLoad: { page: string; id: string } | undefined;\n\nfunction getPageLoadId(page: string): string {\n if (pageLoad?.page !== page) pageLoad = { page, id: randomUUID() };\n return pageLoad.id;\n}\n\nconst links = new Map<string, Promise<Link | null>>();\n\n/**\n * `getTags` runs once per event now, and the link a `?s=` id points at cannot change while the\n * page is open, so an uncached lookup would put an identical request on the wire for every\n * event the page sends.\n */\nfunction getCachedLink(id: string) {\n const cached = links.get(id);\n if (cached) return cached;\n const link = getLink(id).then((result) => {\n // A lookup that came back empty must not stick for the lifetime of the page. `getLink`\n // answers null for a network failure as well as for a link that does not exist, and losing\n // the link's utm params for every later event costs more than repeating a rare request.\n if (!result) links.delete(id);\n return result;\n });\n links.set(id, link);\n return link;\n}\n\n/** The user agent cannot change while the page is open, so it is parsed once. */\nlet parser: ReturnType<typeof Bowser.getParser> | undefined;\n\nexport async function getTags() {\n // Read the page before the first await: `getTags` runs when the event happens, and a single\n // page app can navigate while the link lookup below is still in flight.\n const page_location = window.location.href;\n const page_load_id = getPageLoadId(getPageKey(window.location.pathname, window.location.search));\n const page_referrer = document.referrer || undefined;\n const page_title = document.title;\n\n parser ??= Bowser.getParser(window.navigator.userAgent);\n const params = new URLSearchParams(window.location.search);\n const os = parser.getOS();\n const browser = parser.getBrowser();\n const platform = parser.getPlatform();\n const parsed = parseCookie(document.cookie);\n\n const linkId = params.get('s');\n const link = linkId ? await getCachedLink(linkId) : null;\n\n const tags: TrackTags = {\n os: `${os.name} ${os.version}`,\n os_name: os.name,\n os_version: os.version,\n browser: `${browser.name} ${browser.version}`,\n browser_name: browser.name,\n browser_version: browser.version,\n device: platform.model,\n device_id: getDeviceId(),\n device_type: platform.type,\n device_vendor: platform.vendor,\n device_pixel_ratio: window.devicePixelRatio,\n screen_width: window.screen.width,\n screen_height: window.screen.height,\n screen_resolution: `${window.screen.width}x${window.screen.height}`,\n release: config.release,\n language: navigator.language,\n time_zone: Intl.DateTimeFormat().resolvedOptions().timeZone,\n page_location,\n page_referrer,\n page_title,\n page_load_id,\n // Meta Ads — _fbc is set server-side (see @shware/analytics/server resolveClickIdCookies)\n fbc: parsed._fbc ?? undefined,\n fbp: parsed._fbp,\n fbclid: params.get('fbclid') ?? undefined,\n ad_id: params.get('ad_id') ?? undefined,\n ad_name: params.get('ad_name') ?? undefined,\n adset_id: params.get('adset_id') ?? undefined,\n adset_name: params.get('adset_name') ?? undefined,\n campaign_id: params.get('campaign_id') ?? undefined,\n campaign_name: params.get('campaign_name') ?? undefined,\n placement: params.get('placement') ?? undefined,\n site_source_name: params.get('site_source_name') ?? undefined,\n // Google Ads — _gcl_aw/_gcl_gb are written by gtag and kept alive server-side (see\n // @shware/analytics/server resolveClickIdCookies); the URL wins, the cookie carries the\n // click id to every later page of the visit and to returning visits.\n gclid: params.get('gclid') ?? parseGcl(parsed._gcl_aw)?.clickId,\n gclsrc: params.get('gclsrc') ?? undefined,\n gad_source: params.get('gad_source') ?? undefined,\n gad_campaignid: params.get('gad_campaignid') ?? undefined,\n // Reddit Ads — _rdt_cid is set server-side (see @shware/analytics/server resolveClickIdCookies)\n rdt_cid: params.get('rdt_cid') ?? parsed._rdt_cid ?? undefined,\n rdt_uuid: parsed._rdt_uuid,\n // LinkedIn Ads: get click id from url params or first-party cookie\n li_fat_id: params.get('li_fat_id') ?? parsed.li_fat_id ?? undefined,\n // click ids\n dclid: params.get('dclid') ?? undefined,\n ko_click_id: params.get('ko_click_id') ?? undefined,\n // Microsoft Ads — _uetmsclkid is written by the UET tag and kept alive server-side (see\n // @shware/analytics/server resolveClickIdCookies); the URL wins, the cookie carries the\n // click id to every later page of the visit and to returning visits.\n msclkid: params.get('msclkid') ?? parseUetMsclkid(parsed._uetmsclkid),\n sccid: params.get('sccid') ?? undefined,\n ttclid: params.get('ttclid') ?? undefined,\n twclid: params.get('twclid') ?? undefined,\n wbraid: params.get('wbraid') ?? parseGcl(parsed._gcl_gb)?.clickId,\n gbraid: params.get('gbraid') ?? undefined,\n yclid: params.get('yclid') ?? undefined,\n // utm params\n utm_source: link?.utm_source ?? params.get('utm_source') ?? undefined,\n utm_medium: link?.utm_medium ?? params.get('utm_medium') ?? undefined,\n utm_campaign: link?.utm_campaign ?? params.get('utm_campaign') ?? undefined,\n utm_term: link?.utm_term ?? params.get('utm_term') ?? undefined,\n utm_content: link?.utm_content ?? params.get('utm_content') ?? undefined,\n utm_id: link?.utm_id ?? params.get('utm_id') ?? undefined,\n utm_source_platform:\n link?.utm_source_platform ?? params.get('utm_source_platform') ?? undefined,\n utm_creative_format:\n link?.utm_creative_format ?? params.get('utm_creative_format') ?? undefined,\n utm_marketing_tactic:\n link?.utm_marketing_tactic ?? params.get('utm_marketing_tactic') ?? undefined,\n };\n\n cache.tags = tags;\n return tags;\n}\n\nconst map = new Map<string, string>();\n\nexport const storage: Storage = {\n getItem: (key) => {\n try {\n return localStorage.getItem(key);\n } catch {\n console.error('localStorage is not available');\n return map.get(key) ?? null;\n }\n },\n setItem: (key, value) => {\n try {\n localStorage.setItem(key, value);\n } catch {\n console.error('localStorage is not available');\n map.set(key, value);\n }\n },\n};\n"],"mappings":";;;;;;;;;;;;AAYA,SAAS,aAAqB;CAC5B,OAAQ,OAA2B,aAAa,OAAO,WAAW,KAAA,GAAIA,KAAAA,GAAAA,CAAO;AAC/E;AAEA,SAAgB,cAAc;CAC5B,MAAM,SAASC,oBAAAA,OAAO,QAAQ,QAAQC,0BAAAA,KAAK,SAAS;CACpD,IAAI,QAAQ,OAAO;CACnB,MAAM,KAAK,WAAW;CACtB,oBAAA,OAAO,QAAQ,QAAQA,0BAAAA,KAAK,WAAW,EAAE;CACzC,OAAO;AACT;;;;;;;;;;;AAYA,IAAI;AAEJ,SAAS,cAAc,MAAsB;CAC3C,IAAI,UAAU,SAAS,MAAM,WAAW;EAAE;EAAM,IAAI,WAAW;CAAE;CACjE,OAAO,SAAS;AAClB;AAEA,MAAM,wBAAQ,IAAI,IAAkC;;;;;;AAOpD,SAAS,cAAc,IAAY;CACjC,MAAM,SAAS,MAAM,IAAI,EAAE;CAC3B,IAAI,QAAQ,OAAO;CACnB,MAAM,OAAOC,mBAAAA,QAAQ,EAAE,CAAC,CAAC,MAAM,WAAW;EAIxC,IAAI,CAAC,QAAQ,MAAM,OAAO,EAAE;EAC5B,OAAO;CACT,CAAC;CACD,MAAM,IAAI,IAAI,IAAI;CAClB,OAAO;AACT;;AAGA,IAAI;AAEJ,eAAsB,UAAU;CAG9B,MAAM,gBAAgB,OAAO,SAAS;CACtC,MAAM,eAAe,cAAcC,qBAAAA,WAAW,OAAO,SAAS,UAAU,OAAO,SAAS,MAAM,CAAC;CAC/F,MAAM,gBAAgB,SAAS,YAAY,KAAA;CAC3C,MAAM,aAAa,SAAS;CAE5B,WAAWC,WAAAA,QAAO,UAAU,OAAO,UA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qBAAqB,KAAK,KAAA;EACpE,sBACE,MAAM,wBAAwB,OAAO,IAAI,sBAAsB,KAAK,KAAA;CACxE;CAEA,oBAAA,MAAM,OAAO;CACb,OAAO;AACT;AAEA,MAAM,sBAAM,IAAI,IAAoB;AAEpC,MAAa,UAAmB;CAC9B,UAAU,QAAQ;EAChB,IAAI;GACF,OAAO,aAAa,QAAQ,GAAG;EACjC,QAAQ;GACN,QAAQ,MAAM,+BAA+B;GAC7C,OAAO,IAAI,IAAI,GAAG,KAAK;EACzB;CACF;CACA,UAAU,KAAK,UAAU;EACvB,IAAI;GACF,aAAa,QAAQ,KAAK,KAAK;EACjC,QAAQ;GACN,QAAQ,MAAM,+BAA+B;GAC7C,IAAI,IAAI,KAAK,KAAK;EACpB;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/web/index.ts"],"mappings":";;;iBASgB;iBAkCM,WAAO,QAAA;cAgGhB,SAAS"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/web/index.ts"],"mappings":";;;iBAgBgB;iBAiDM,WAAO,QAAA;cAkGhB,SAAS"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/web/index.ts"],"mappings":";;;iBASgB;iBAkCM,WAAO,QAAA;cAgGhB,SAAS"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/web/index.ts"],"mappings":";;;iBAgBgB;iBAiDM,WAAO,QAAA;cAkGhB,SAAS"}
@@ -3,18 +3,40 @@ import { cache, config } from "../setup/index.mjs";
3
3
  import { keys } from "../constants/storage.mjs";
4
4
  import { getLink } from "../link/index.mjs";
5
5
  import { parseGcl, parseUetMsclkid } from "../click-id/index.mjs";
6
+ import { getPageKey } from "./page-key.mjs";
6
7
  import { require_es5 } from "../node_modules/.pnpm/bowser@2.14.1/node_modules/bowser/es5.mjs";
7
8
  import { v4 } from "uuid";
8
9
  import { parseCookie } from "cookie";
9
10
  //#region src/web/index.ts
10
11
  var import_es5 = /* @__PURE__ */ __toESM(require_es5(), 1);
12
+ function randomUUID() {
13
+ return crypto.randomUUID ? crypto.randomUUID() : v4();
14
+ }
11
15
  function getDeviceId() {
12
16
  const cached = config.storage.getItem(keys.device_id);
13
17
  if (cached) return cached;
14
- const id = crypto.randomUUID ? crypto.randomUUID() : v4();
18
+ const id = randomUUID();
15
19
  config.storage.setItem(keys.device_id, id);
16
20
  return id;
17
21
  }
22
+ /**
23
+ * The current page load, keyed by the page it was loaded at. A module variable and nothing more
24
+ * persistent: the id must die with the page (a reload is a new page load, and storage would
25
+ * carry it over — or, shared across tabs, let two pages overwrite each other's).
26
+ *
27
+ * Keyed by `getPageKey` because that is what the SDK's own `page_view` fires on (see
28
+ * `useWebAnalytics`): the id exists to link an event to the `page_view` of the page it happened
29
+ * on, so it must rotate exactly when a `page_view` is sent — path or query change, yes; hash
30
+ * change or tracking-parameter cleanup, no.
31
+ */
32
+ let pageLoad;
33
+ function getPageLoadId(page) {
34
+ if (pageLoad?.page !== page) pageLoad = {
35
+ page,
36
+ id: randomUUID()
37
+ };
38
+ return pageLoad.id;
39
+ }
18
40
  const links = /* @__PURE__ */ new Map();
19
41
  /**
20
42
  * `getTags` runs once per event now, and the link a `?s=` id points at cannot change while the
@@ -35,6 +57,7 @@ function getCachedLink(id) {
35
57
  let parser;
36
58
  async function getTags() {
37
59
  const page_location = window.location.href;
60
+ const page_load_id = getPageLoadId(getPageKey(window.location.pathname, window.location.search));
38
61
  const page_referrer = document.referrer || void 0;
39
62
  const page_title = document.title;
40
63
  parser ??= import_es5.default.getParser(window.navigator.userAgent);
@@ -66,6 +89,7 @@ async function getTags() {
66
89
  page_location,
67
90
  page_referrer,
68
91
  page_title,
92
+ page_load_id,
69
93
  fbc: parsed._fbc ?? void 0,
70
94
  fbp: parsed._fbp,
71
95
  fbclid: params.get("fbclid") ?? void 0,
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["uuidv4","Bowser"],"sources":["../../src/web/index.ts"],"sourcesContent":["import Bowser from 'bowser';\nimport { parseCookie } from 'cookie';\nimport { v4 as uuidv4 } from 'uuid';\nimport { parseGcl, parseUetMsclkid } from '../click-id/index';\nimport { keys } from '../constants/storage';\nimport { type Link, getLink } from '../link/index';\nimport { type Storage, cache, config } from '../setup/index';\nimport type { TrackTags } from '../track/types';\n\nexport function getDeviceId() {\n const cached = config.storage.getItem(keys.device_id);\n if (cached) return cached;\n // lib.dom types `crypto.randomUUID` as always present, but it is missing in\n // insecure contexts and older browsers, so probe it before use.\n const id = (crypto as Partial<Crypto>).randomUUID ? crypto.randomUUID() : uuidv4();\n config.storage.setItem(keys.device_id, id);\n return id;\n}\n\nconst links = new Map<string, Promise<Link | null>>();\n\n/**\n * `getTags` runs once per event now, and the link a `?s=` id points at cannot change while the\n * page is open, so an uncached lookup would put an identical request on the wire for every\n * event the page sends.\n */\nfunction getCachedLink(id: string) {\n const cached = links.get(id);\n if (cached) return cached;\n const link = getLink(id).then((result) => {\n // A lookup that came back empty must not stick for the lifetime of the page. `getLink`\n // answers null for a network failure as well as for a link that does not exist, and losing\n // the link's utm params for every later event costs more than repeating a rare request.\n if (!result) links.delete(id);\n return result;\n });\n links.set(id, link);\n return link;\n}\n\n/** The user agent cannot change while the page is open, so it is parsed once. */\nlet parser: ReturnType<typeof Bowser.getParser> | undefined;\n\nexport async function getTags() {\n // Read the page before the first await: `getTags` runs when the event happens, and a single\n // page app can navigate while the link lookup below is still in flight.\n const page_location = window.location.href;\n const page_referrer = document.referrer || undefined;\n const page_title = document.title;\n\n parser ??= Bowser.getParser(window.navigator.userAgent);\n const params = new URLSearchParams(window.location.search);\n const os = parser.getOS();\n const browser = parser.getBrowser();\n const platform = parser.getPlatform();\n const parsed = parseCookie(document.cookie);\n\n const linkId = params.get('s');\n const link = linkId ? await getCachedLink(linkId) : null;\n\n const tags: TrackTags = {\n os: `${os.name} ${os.version}`,\n os_name: os.name,\n os_version: os.version,\n browser: `${browser.name} ${browser.version}`,\n browser_name: browser.name,\n browser_version: browser.version,\n device: platform.model,\n device_id: getDeviceId(),\n device_type: platform.type,\n device_vendor: platform.vendor,\n device_pixel_ratio: window.devicePixelRatio,\n screen_width: window.screen.width,\n screen_height: window.screen.height,\n screen_resolution: `${window.screen.width}x${window.screen.height}`,\n release: config.release,\n language: navigator.language,\n time_zone: Intl.DateTimeFormat().resolvedOptions().timeZone,\n page_location,\n page_referrer,\n page_title,\n // Meta Ads — _fbc is set server-side (see @shware/analytics/server resolveClickIdCookies)\n fbc: parsed._fbc ?? undefined,\n fbp: parsed._fbp,\n fbclid: params.get('fbclid') ?? undefined,\n ad_id: params.get('ad_id') ?? undefined,\n ad_name: params.get('ad_name') ?? undefined,\n adset_id: params.get('adset_id') ?? undefined,\n adset_name: params.get('adset_name') ?? undefined,\n campaign_id: params.get('campaign_id') ?? undefined,\n campaign_name: params.get('campaign_name') ?? undefined,\n placement: params.get('placement') ?? undefined,\n site_source_name: params.get('site_source_name') ?? undefined,\n // Google Ads — _gcl_aw/_gcl_gb are written by gtag and kept alive server-side (see\n // @shware/analytics/server resolveClickIdCookies); the URL wins, the cookie carries the\n // click id to every later page of the visit and to returning visits.\n gclid: params.get('gclid') ?? parseGcl(parsed._gcl_aw)?.clickId,\n gclsrc: params.get('gclsrc') ?? undefined,\n gad_source: params.get('gad_source') ?? undefined,\n gad_campaignid: params.get('gad_campaignid') ?? undefined,\n // Reddit Ads — _rdt_cid is set server-side (see @shware/analytics/server resolveClickIdCookies)\n rdt_cid: params.get('rdt_cid') ?? parsed._rdt_cid ?? undefined,\n rdt_uuid: parsed._rdt_uuid,\n // LinkedIn Ads: get click id from url params or first-party cookie\n li_fat_id: params.get('li_fat_id') ?? parsed.li_fat_id ?? undefined,\n // click ids\n dclid: params.get('dclid') ?? undefined,\n ko_click_id: params.get('ko_click_id') ?? undefined,\n // Microsoft Ads — _uetmsclkid is written by the UET tag and kept alive server-side (see\n // @shware/analytics/server resolveClickIdCookies); the URL wins, the cookie carries the\n // click id to every later page of the visit and to returning visits.\n msclkid: params.get('msclkid') ?? parseUetMsclkid(parsed._uetmsclkid),\n sccid: params.get('sccid') ?? undefined,\n ttclid: params.get('ttclid') ?? undefined,\n twclid: params.get('twclid') ?? undefined,\n wbraid: params.get('wbraid') ?? parseGcl(parsed._gcl_gb)?.clickId,\n gbraid: params.get('gbraid') ?? undefined,\n yclid: params.get('yclid') ?? undefined,\n // utm params\n utm_source: link?.utm_source ?? params.get('utm_source') ?? undefined,\n utm_medium: link?.utm_medium ?? params.get('utm_medium') ?? undefined,\n utm_campaign: link?.utm_campaign ?? params.get('utm_campaign') ?? undefined,\n utm_term: link?.utm_term ?? params.get('utm_term') ?? undefined,\n utm_content: link?.utm_content ?? params.get('utm_content') ?? undefined,\n utm_id: link?.utm_id ?? params.get('utm_id') ?? undefined,\n utm_source_platform:\n link?.utm_source_platform ?? params.get('utm_source_platform') ?? undefined,\n utm_creative_format:\n link?.utm_creative_format ?? params.get('utm_creative_format') ?? undefined,\n utm_marketing_tactic:\n link?.utm_marketing_tactic ?? params.get('utm_marketing_tactic') ?? undefined,\n };\n\n cache.tags = tags;\n return tags;\n}\n\nconst map = new Map<string, string>();\n\nexport const storage: Storage = {\n getItem: (key) => {\n try {\n return localStorage.getItem(key);\n } catch {\n console.error('localStorage is not available');\n return map.get(key) ?? null;\n }\n },\n setItem: (key, value) => {\n try {\n localStorage.setItem(key, value);\n } catch {\n console.error('localStorage is not available');\n map.set(key, value);\n }\n },\n};\n"],"mappings":";;;;;;;;;;AASA,SAAgB,cAAc;CAC5B,MAAM,SAAS,OAAO,QAAQ,QAAQ,KAAK,SAAS;CACpD,IAAI,QAAQ,OAAO;CAGnB,MAAM,KAAM,OAA2B,aAAa,OAAO,WAAW,IAAIA,GAAO;CACjF,OAAO,QAAQ,QAAQ,KAAK,WAAW,EAAE;CACzC,OAAO;AACT;AAEA,MAAM,wBAAQ,IAAI,IAAkC;;;;;;AAOpD,SAAS,cAAc,IAAY;CACjC,MAAM,SA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,KAAA;EAC5D,cAAc,MAAM,gBAAgB,OAAO,IAAI,cAAc,KAAK,KAAA;EAClE,UAAU,MAAM,YAAY,OAAO,IAAI,UAAU,KAAK,KAAA;EACtD,aAAa,MAAM,eAAe,OAAO,IAAI,aAAa,KAAK,KAAA;EAC/D,QAAQ,MAAM,UAAU,OAAO,IAAI,QAAQ,KAAK,KAAA;EAChD,qBACE,MAAM,uBAAuB,OAAO,IAAI,qBAAqB,KAAK,KAAA;EACpE,qBACE,MAAM,uBAAuB,OAAO,IAAI,qBAAqB,KAAK,KAAA;EACpE,sBACE,MAAM,wBAAwB,OAAO,IAAI,sBAAsB,KAAK,KAAA;CACxE;CAEA,MAAM,OAAO;CACb,OAAO;AACT;AAEA,MAAM,sBAAM,IAAI,IAAoB;AAEpC,MAAa,UAAmB;CAC9B,UAAU,QAAQ;EAChB,IAAI;GACF,OAAO,aAAa,QAAQ,GAAG;EACjC,QAAQ;GACN,QAAQ,MAAM,+BAA+B;GAC7C,OAAO,IAAI,IAAI,GAAG,KAAK;EACzB;CACF;CACA,UAAU,KAAK,UAAU;EACvB,IAAI;GACF,aAAa,QAAQ,KAAK,KAAK;EACjC,QAAQ;GACN,QAAQ,MAAM,+BAA+B;GAC7C,IAAI,IAAI,KAAK,KAAK;EACpB;CACF;AACF"}
1
+ {"version":3,"file":"index.mjs","names":["uuidv4","Bowser"],"sources":["../../src/web/index.ts"],"sourcesContent":["import Bowser from 'bowser';\nimport { parseCookie } from 'cookie';\nimport { v4 as uuidv4 } from 'uuid';\nimport { parseGcl, parseUetMsclkid } from '../click-id/index';\nimport { keys } from '../constants/storage';\nimport { type Link, getLink } from '../link/index';\nimport { type Storage, cache, config } from '../setup/index';\nimport type { TrackTags } from '../track/types';\nimport { getPageKey } from './page-key';\n\n// lib.dom types `crypto.randomUUID` as always present, but it is missing in insecure contexts\n// and older browsers, so probe it before use.\nfunction randomUUID(): string {\n return (crypto as Partial<Crypto>).randomUUID ? crypto.randomUUID() : uuidv4();\n}\n\nexport function getDeviceId() {\n const cached = config.storage.getItem(keys.device_id);\n if (cached) return cached;\n const id = randomUUID();\n config.storage.setItem(keys.device_id, id);\n return id;\n}\n\n/**\n * The current page load, keyed by the page it was loaded at. A module variable and nothing more\n * persistent: the id must die with the page (a reload is a new page load, and storage would\n * carry it over — or, shared across tabs, let two pages overwrite each other's).\n *\n * Keyed by `getPageKey` because that is what the SDK's own `page_view` fires on (see\n * `useWebAnalytics`): the id exists to link an event to the `page_view` of the page it happened\n * on, so it must rotate exactly when a `page_view` is sent — path or query change, yes; hash\n * change or tracking-parameter cleanup, no.\n */\nlet pageLoad: { page: string; id: string } | undefined;\n\nfunction getPageLoadId(page: string): string {\n if (pageLoad?.page !== page) pageLoad = { page, id: randomUUID() };\n return pageLoad.id;\n}\n\nconst links = new Map<string, Promise<Link | null>>();\n\n/**\n * `getTags` runs once per event now, and the link a `?s=` id points at cannot change while the\n * page is open, so an uncached lookup would put an identical request on the wire for every\n * event the page sends.\n */\nfunction getCachedLink(id: string) {\n const cached = links.get(id);\n if (cached) return cached;\n const link = getLink(id).then((result) => {\n // A lookup that came back empty must not stick for the lifetime of the page. `getLink`\n // answers null for a network failure as well as for a link that does not exist, and losing\n // the link's utm params for every later event costs more than repeating a rare request.\n if (!result) links.delete(id);\n return result;\n });\n links.set(id, link);\n return link;\n}\n\n/** The user agent cannot change while the page is open, so it is parsed once. */\nlet parser: ReturnType<typeof Bowser.getParser> | undefined;\n\nexport async function getTags() {\n // Read the page before the first await: `getTags` runs when the event happens, and a single\n // page app can navigate while the link lookup below is still in flight.\n const page_location = window.location.href;\n const page_load_id = getPageLoadId(getPageKey(window.location.pathname, window.location.search));\n const page_referrer = document.referrer || undefined;\n const page_title = document.title;\n\n parser ??= Bowser.getParser(window.navigator.userAgent);\n const params = new URLSearchParams(window.location.search);\n const os = parser.getOS();\n const browser = parser.getBrowser();\n const platform = parser.getPlatform();\n const parsed = parseCookie(document.cookie);\n\n const linkId = params.get('s');\n const link = linkId ? await getCachedLink(linkId) : null;\n\n const tags: TrackTags = {\n os: `${os.name} ${os.version}`,\n os_name: os.name,\n os_version: os.version,\n browser: `${browser.name} ${browser.version}`,\n browser_name: browser.name,\n browser_version: browser.version,\n device: platform.model,\n device_id: getDeviceId(),\n device_type: platform.type,\n device_vendor: platform.vendor,\n device_pixel_ratio: window.devicePixelRatio,\n screen_width: window.screen.width,\n screen_height: window.screen.height,\n screen_resolution: `${window.screen.width}x${window.screen.height}`,\n release: config.release,\n language: navigator.language,\n time_zone: Intl.DateTimeFormat().resolvedOptions().timeZone,\n page_location,\n page_referrer,\n page_title,\n page_load_id,\n // Meta Ads — _fbc is set server-side (see @shware/analytics/server resolveClickIdCookies)\n fbc: parsed._fbc ?? undefined,\n fbp: parsed._fbp,\n fbclid: params.get('fbclid') ?? undefined,\n ad_id: params.get('ad_id') ?? undefined,\n ad_name: params.get('ad_name') ?? undefined,\n adset_id: params.get('adset_id') ?? undefined,\n adset_name: params.get('adset_name') ?? undefined,\n campaign_id: params.get('campaign_id') ?? undefined,\n campaign_name: params.get('campaign_name') ?? undefined,\n placement: params.get('placement') ?? undefined,\n site_source_name: params.get('site_source_name') ?? undefined,\n // Google Ads — _gcl_aw/_gcl_gb are written by gtag and kept alive server-side (see\n // @shware/analytics/server resolveClickIdCookies); the URL wins, the cookie carries the\n // click id to every later page of the visit and to returning visits.\n gclid: params.get('gclid') ?? parseGcl(parsed._gcl_aw)?.clickId,\n gclsrc: params.get('gclsrc') ?? undefined,\n gad_source: params.get('gad_source') ?? undefined,\n gad_campaignid: params.get('gad_campaignid') ?? undefined,\n // Reddit Ads — _rdt_cid is set server-side (see @shware/analytics/server resolveClickIdCookies)\n rdt_cid: params.get('rdt_cid') ?? parsed._rdt_cid ?? undefined,\n rdt_uuid: parsed._rdt_uuid,\n // LinkedIn Ads: get click id from url params or first-party cookie\n li_fat_id: params.get('li_fat_id') ?? parsed.li_fat_id ?? undefined,\n // click ids\n dclid: params.get('dclid') ?? undefined,\n ko_click_id: params.get('ko_click_id') ?? undefined,\n // Microsoft Ads — _uetmsclkid is written by the UET tag and kept alive server-side (see\n // @shware/analytics/server resolveClickIdCookies); the URL wins, the cookie carries the\n // click id to every later page of the visit and to returning visits.\n msclkid: params.get('msclkid') ?? parseUetMsclkid(parsed._uetmsclkid),\n sccid: params.get('sccid') ?? undefined,\n ttclid: params.get('ttclid') ?? undefined,\n twclid: params.get('twclid') ?? undefined,\n wbraid: params.get('wbraid') ?? parseGcl(parsed._gcl_gb)?.clickId,\n gbraid: params.get('gbraid') ?? undefined,\n yclid: params.get('yclid') ?? undefined,\n // utm params\n utm_source: link?.utm_source ?? params.get('utm_source') ?? undefined,\n utm_medium: link?.utm_medium ?? params.get('utm_medium') ?? undefined,\n utm_campaign: link?.utm_campaign ?? params.get('utm_campaign') ?? undefined,\n utm_term: link?.utm_term ?? params.get('utm_term') ?? undefined,\n utm_content: link?.utm_content ?? params.get('utm_content') ?? undefined,\n utm_id: link?.utm_id ?? params.get('utm_id') ?? undefined,\n utm_source_platform:\n link?.utm_source_platform ?? params.get('utm_source_platform') ?? undefined,\n utm_creative_format:\n link?.utm_creative_format ?? params.get('utm_creative_format') ?? undefined,\n utm_marketing_tactic:\n link?.utm_marketing_tactic ?? params.get('utm_marketing_tactic') ?? undefined,\n };\n\n cache.tags = tags;\n return tags;\n}\n\nconst map = new Map<string, string>();\n\nexport const storage: Storage = {\n getItem: (key) => {\n try {\n return localStorage.getItem(key);\n } catch {\n console.error('localStorage is not available');\n return map.get(key) ?? null;\n }\n },\n setItem: (key, value) => {\n try {\n localStorage.setItem(key, value);\n } catch {\n console.error('localStorage is not available');\n map.set(key, value);\n }\n },\n};\n"],"mappings":";;;;;;;;;;;AAYA,SAAS,aAAqB;CAC5B,OAAQ,OAA2B,aAAa,OAAO,WAAW,IAAIA,GAAO;AAC/E;AAEA,SAAgB,cAAc;CAC5B,MAAM,SAAS,OAAO,QAAQ,QAAQ,KAAK,SAAS;CACpD,IAAI,QAAQ,OAAO;CACnB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ringTag, { value: "Module" });
2
+ //#region src/web/page-key.ts
3
+ /**
4
+ * What makes two URLs "the same page" for page views and the page load id.
5
+ *
6
+ * Path plus query, in line with GA4's enhanced measurement (a history change with a new path
7
+ * or query is a page view), Next.js's documented pattern (`usePathname` + `useSearchParams`)
8
+ * and PostHog's `history_change`: `?page=2` and `?q=shoes` are different pages to a funnel.
9
+ * The hash is not part of it — an in-page anchor is not a navigation, and GA4 ignores
10
+ * fragment-only changes by default too.
11
+ *
12
+ * Tracking parameters are stripped before comparing. A landing page commonly cleans `utm_*`
13
+ * and the ad click ids out of its URL with `replaceState` once they are captured; keyed on the
14
+ * raw query, that cleanup would count as a second page view of the landing page. (GA4 has this
15
+ * quirk; the usual advice is to strip before comparing.) The parameters are the ones `getTags`
16
+ * captures — nothing a page's own state lives in.
17
+ */
18
+ const TRACKING_PARAMS = /* @__PURE__ */ new Set([
19
+ "fbclid",
20
+ "gclid",
21
+ "gclsrc",
22
+ "gad_source",
23
+ "gad_campaignid",
24
+ "gbraid",
25
+ "wbraid",
26
+ "dclid",
27
+ "msclkid",
28
+ "rdt_cid",
29
+ "li_fat_id",
30
+ "ttclid",
31
+ "twclid",
32
+ "sccid",
33
+ "ko_click_id",
34
+ "yclid"
35
+ ]);
36
+ function isTrackingParam(name) {
37
+ return name.startsWith("utm_") || TRACKING_PARAMS.has(name);
38
+ }
39
+ /**
40
+ * `pathname` plus the query with tracking parameters removed and the rest sorted, so two URLs
41
+ * that differ only in tracking decoration or parameter order map to one key.
42
+ */
43
+ function getPageKey(pathname, search = "") {
44
+ const params = new URLSearchParams(search);
45
+ for (const name of Array.from(params.keys())) if (isTrackingParam(name)) params.delete(name);
46
+ params.sort();
47
+ const query = params.toString();
48
+ return query ? `${pathname}?${query}` : pathname;
49
+ }
50
+ //#endregion
51
+ exports.getPageKey = getPageKey;
52
+
53
+ //# sourceMappingURL=page-key.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-key.cjs","names":[],"sources":["../../src/web/page-key.ts"],"sourcesContent":["/**\n * What makes two URLs \"the same page\" for page views and the page load id.\n *\n * Path plus query, in line with GA4's enhanced measurement (a history change with a new path\n * or query is a page view), Next.js's documented pattern (`usePathname` + `useSearchParams`)\n * and PostHog's `history_change`: `?page=2` and `?q=shoes` are different pages to a funnel.\n * The hash is not part of it — an in-page anchor is not a navigation, and GA4 ignores\n * fragment-only changes by default too.\n *\n * Tracking parameters are stripped before comparing. A landing page commonly cleans `utm_*`\n * and the ad click ids out of its URL with `replaceState` once they are captured; keyed on the\n * raw query, that cleanup would count as a second page view of the landing page. (GA4 has this\n * quirk; the usual advice is to strip before comparing.) The parameters are the ones `getTags`\n * captures — nothing a page's own state lives in.\n */\n\nconst TRACKING_PARAMS = new Set([\n 'fbclid',\n 'gclid',\n 'gclsrc',\n 'gad_source',\n 'gad_campaignid',\n 'gbraid',\n 'wbraid',\n 'dclid',\n 'msclkid',\n 'rdt_cid',\n 'li_fat_id',\n 'ttclid',\n 'twclid',\n 'sccid',\n 'ko_click_id',\n 'yclid',\n]);\n\nfunction isTrackingParam(name: string): boolean {\n return name.startsWith('utm_') || TRACKING_PARAMS.has(name);\n}\n\n/**\n * `pathname` plus the query with tracking parameters removed and the rest sorted, so two URLs\n * that differ only in tracking decoration or parameter order map to one key.\n */\nexport function getPageKey(pathname: string, search = ''): string {\n const params = new URLSearchParams(search);\n for (const name of Array.from(params.keys())) {\n if (isTrackingParam(name)) params.delete(name);\n }\n params.sort();\n const query = params.toString();\n return query ? `${pathname}?${query}` : pathname;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,MAAM,kCAAkB,IAAI,IAAI;CAC9B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAS,gBAAgB,MAAuB;CAC9C,OAAO,KAAK,WAAW,MAAM,KAAK,gBAAgB,IAAI,IAAI;AAC5D;;;;;AAMA,SAAgB,WAAW,UAAkB,SAAS,IAAY;CAChE,MAAM,SAAS,IAAI,gBAAgB,MAAM;CACzC,KAAK,MAAM,QAAQ,MAAM,KAAK,OAAO,KAAK,CAAC,GACzC,IAAI,gBAAgB,IAAI,GAAG,OAAO,OAAO,IAAI;CAE/C,OAAO,KAAK;CACZ,MAAM,QAAQ,OAAO,SAAS;CAC9B,OAAO,QAAQ,GAAG,SAAS,GAAG,UAAU;AAC1C"}
@@ -0,0 +1,24 @@
1
+ //#region src/web/page-key.d.ts
2
+ /**
3
+ * What makes two URLs "the same page" for page views and the page load id.
4
+ *
5
+ * Path plus query, in line with GA4's enhanced measurement (a history change with a new path
6
+ * or query is a page view), Next.js's documented pattern (`usePathname` + `useSearchParams`)
7
+ * and PostHog's `history_change`: `?page=2` and `?q=shoes` are different pages to a funnel.
8
+ * The hash is not part of it — an in-page anchor is not a navigation, and GA4 ignores
9
+ * fragment-only changes by default too.
10
+ *
11
+ * Tracking parameters are stripped before comparing. A landing page commonly cleans `utm_*`
12
+ * and the ad click ids out of its URL with `replaceState` once they are captured; keyed on the
13
+ * raw query, that cleanup would count as a second page view of the landing page. (GA4 has this
14
+ * quirk; the usual advice is to strip before comparing.) The parameters are the ones `getTags`
15
+ * captures — nothing a page's own state lives in.
16
+ */
17
+ /**
18
+ * `pathname` plus the query with tracking parameters removed and the rest sorted, so two URLs
19
+ * that differ only in tracking decoration or parameter order map to one key.
20
+ */
21
+ declare function getPageKey(pathname: string, search?: string): string;
22
+ //#endregion
23
+ export { getPageKey };
24
+ //# sourceMappingURL=page-key.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-key.d.cts","names":[],"sources":["../../src/web/page-key.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;iBA2CgB,WAAW,kBAAkB"}
@@ -0,0 +1,24 @@
1
+ //#region src/web/page-key.d.ts
2
+ /**
3
+ * What makes two URLs "the same page" for page views and the page load id.
4
+ *
5
+ * Path plus query, in line with GA4's enhanced measurement (a history change with a new path
6
+ * or query is a page view), Next.js's documented pattern (`usePathname` + `useSearchParams`)
7
+ * and PostHog's `history_change`: `?page=2` and `?q=shoes` are different pages to a funnel.
8
+ * The hash is not part of it — an in-page anchor is not a navigation, and GA4 ignores
9
+ * fragment-only changes by default too.
10
+ *
11
+ * Tracking parameters are stripped before comparing. A landing page commonly cleans `utm_*`
12
+ * and the ad click ids out of its URL with `replaceState` once they are captured; keyed on the
13
+ * raw query, that cleanup would count as a second page view of the landing page. (GA4 has this
14
+ * quirk; the usual advice is to strip before comparing.) The parameters are the ones `getTags`
15
+ * captures — nothing a page's own state lives in.
16
+ */
17
+ /**
18
+ * `pathname` plus the query with tracking parameters removed and the rest sorted, so two URLs
19
+ * that differ only in tracking decoration or parameter order map to one key.
20
+ */
21
+ declare function getPageKey(pathname: string, search?: string): string;
22
+ //#endregion
23
+ export { getPageKey };
24
+ //# sourceMappingURL=page-key.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-key.d.mts","names":[],"sources":["../../src/web/page-key.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;iBA2CgB,WAAW,kBAAkB"}
@@ -0,0 +1,52 @@
1
+ //#region src/web/page-key.ts
2
+ /**
3
+ * What makes two URLs "the same page" for page views and the page load id.
4
+ *
5
+ * Path plus query, in line with GA4's enhanced measurement (a history change with a new path
6
+ * or query is a page view), Next.js's documented pattern (`usePathname` + `useSearchParams`)
7
+ * and PostHog's `history_change`: `?page=2` and `?q=shoes` are different pages to a funnel.
8
+ * The hash is not part of it — an in-page anchor is not a navigation, and GA4 ignores
9
+ * fragment-only changes by default too.
10
+ *
11
+ * Tracking parameters are stripped before comparing. A landing page commonly cleans `utm_*`
12
+ * and the ad click ids out of its URL with `replaceState` once they are captured; keyed on the
13
+ * raw query, that cleanup would count as a second page view of the landing page. (GA4 has this
14
+ * quirk; the usual advice is to strip before comparing.) The parameters are the ones `getTags`
15
+ * captures — nothing a page's own state lives in.
16
+ */
17
+ const TRACKING_PARAMS = /* @__PURE__ */ new Set([
18
+ "fbclid",
19
+ "gclid",
20
+ "gclsrc",
21
+ "gad_source",
22
+ "gad_campaignid",
23
+ "gbraid",
24
+ "wbraid",
25
+ "dclid",
26
+ "msclkid",
27
+ "rdt_cid",
28
+ "li_fat_id",
29
+ "ttclid",
30
+ "twclid",
31
+ "sccid",
32
+ "ko_click_id",
33
+ "yclid"
34
+ ]);
35
+ function isTrackingParam(name) {
36
+ return name.startsWith("utm_") || TRACKING_PARAMS.has(name);
37
+ }
38
+ /**
39
+ * `pathname` plus the query with tracking parameters removed and the rest sorted, so two URLs
40
+ * that differ only in tracking decoration or parameter order map to one key.
41
+ */
42
+ function getPageKey(pathname, search = "") {
43
+ const params = new URLSearchParams(search);
44
+ for (const name of Array.from(params.keys())) if (isTrackingParam(name)) params.delete(name);
45
+ params.sort();
46
+ const query = params.toString();
47
+ return query ? `${pathname}?${query}` : pathname;
48
+ }
49
+ //#endregion
50
+ export { getPageKey };
51
+
52
+ //# sourceMappingURL=page-key.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-key.mjs","names":[],"sources":["../../src/web/page-key.ts"],"sourcesContent":["/**\n * What makes two URLs \"the same page\" for page views and the page load id.\n *\n * Path plus query, in line with GA4's enhanced measurement (a history change with a new path\n * or query is a page view), Next.js's documented pattern (`usePathname` + `useSearchParams`)\n * and PostHog's `history_change`: `?page=2` and `?q=shoes` are different pages to a funnel.\n * The hash is not part of it — an in-page anchor is not a navigation, and GA4 ignores\n * fragment-only changes by default too.\n *\n * Tracking parameters are stripped before comparing. A landing page commonly cleans `utm_*`\n * and the ad click ids out of its URL with `replaceState` once they are captured; keyed on the\n * raw query, that cleanup would count as a second page view of the landing page. (GA4 has this\n * quirk; the usual advice is to strip before comparing.) The parameters are the ones `getTags`\n * captures — nothing a page's own state lives in.\n */\n\nconst TRACKING_PARAMS = new Set([\n 'fbclid',\n 'gclid',\n 'gclsrc',\n 'gad_source',\n 'gad_campaignid',\n 'gbraid',\n 'wbraid',\n 'dclid',\n 'msclkid',\n 'rdt_cid',\n 'li_fat_id',\n 'ttclid',\n 'twclid',\n 'sccid',\n 'ko_click_id',\n 'yclid',\n]);\n\nfunction isTrackingParam(name: string): boolean {\n return name.startsWith('utm_') || TRACKING_PARAMS.has(name);\n}\n\n/**\n * `pathname` plus the query with tracking parameters removed and the rest sorted, so two URLs\n * that differ only in tracking decoration or parameter order map to one key.\n */\nexport function getPageKey(pathname: string, search = ''): string {\n const params = new URLSearchParams(search);\n for (const name of Array.from(params.keys())) {\n if (isTrackingParam(name)) params.delete(name);\n }\n params.sort();\n const query = params.toString();\n return query ? `${pathname}?${query}` : pathname;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,MAAM,kCAAkB,IAAI,IAAI;CAC9B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAS,gBAAgB,MAAuB;CAC9C,OAAO,KAAK,WAAW,MAAM,KAAK,gBAAgB,IAAI,IAAI;AAC5D;;;;;AAMA,SAAgB,WAAW,UAAkB,SAAS,IAAY;CAChE,MAAM,SAAS,IAAI,gBAAgB,MAAM;CACzC,KAAK,MAAM,QAAQ,MAAM,KAAK,OAAO,KAAK,CAAC,GACzC,IAAI,gBAAgB,IAAI,GAAG,OAAO,OAAO,IAAI;CAE/C,OAAO,KAAK;CACZ,MAAM,QAAQ,OAAO,SAAS;CAC9B,OAAO,QAAQ,GAAG,SAAS,GAAG,UAAU;AAC1C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/analytics",
3
- "version": "8.3.0",
3
+ "version": "8.6.0",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",