@hanzo/rooms 0.1.47 → 0.1.48

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.
@@ -54,6 +54,21 @@ export declare function door(): string;
54
54
  * the page is `door()`'s; a control that says "Sign in" names LOGIN.
55
55
  */
56
56
  export declare function enter(to?: string): void;
57
+ /**
58
+ * The campaign a visit arrived with: the UTM parameters and the ad platforms'
59
+ * click ids. They ride to the sign-in page as its own parameters, so the page a
60
+ * campaign's visitor signs up on is a landing with that campaign, not one with
61
+ * it folded inside `next=`.
62
+ */
63
+ export declare const CAMPAIGN: readonly ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "gclid", "gbraid", "wbraid", "fbclid", "li_fat_id", "twclid", "ttclid"];
64
+ /**
65
+ * The sign-in address for a reader on `here`: `to`, with `here` as its `next=`
66
+ * when that is a page worth coming back to, and the campaign `here` carries as
67
+ * `to`'s own parameters. The page itself is written in the address too, so the
68
+ * place (a room, a prompt in `?q=`) survives what sessionStorage does not: a new
69
+ * tab, a pasted link.
70
+ */
71
+ export declare function entry(to: string, here: string): string;
57
72
  /**
58
73
  * The `?next=` a sign-in page was opened with, when it is an address on this
59
74
  * site (`safe`): where the sign-in goes on to. Anything else is undefined.
@@ -119,10 +119,39 @@ export function enter(to = door()) {
119
119
  if (handoff(here))
120
120
  return;
121
121
  rememberDestination();
122
- // Written in the address too, so the place (a room, a prompt in `?q=`)
123
- // survives what sessionStorage does not: a new tab, a pasted link.
122
+ window.location.assign(entry(to, here));
123
+ }
124
+ /**
125
+ * The campaign a visit arrived with: the UTM parameters and the ad platforms'
126
+ * click ids. They ride to the sign-in page as its own parameters, so the page a
127
+ * campaign's visitor signs up on is a landing with that campaign, not one with
128
+ * it folded inside `next=`.
129
+ */
130
+ export const CAMPAIGN = [
131
+ "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content",
132
+ "gclid", "gbraid", "wbraid", "fbclid", "li_fat_id", "twclid", "ttclid",
133
+ ];
134
+ /**
135
+ * The sign-in address for a reader on `here`: `to`, with `here` as its `next=`
136
+ * when that is a page worth coming back to, and the campaign `here` carries as
137
+ * `to`'s own parameters. The page itself is written in the address too, so the
138
+ * place (a room, a prompt in `?q=`) survives what sessionStorage does not: a new
139
+ * tab, a pasted link.
140
+ */
141
+ export function entry(to, here) {
142
+ const [path, query = ""] = to.split("?");
143
+ const out = new URLSearchParams(query);
124
144
  const back = safe(here, "");
125
- window.location.assign(back && back !== "/" ? `${to}?next=${encodeURIComponent(back)}` : to);
145
+ if (back && back !== "/")
146
+ out.set("next", back);
147
+ const from = new URLSearchParams(here.split("#")[0].split("?")[1] ?? "");
148
+ for (const k of CAMPAIGN) {
149
+ const v = from.get(k)?.trim();
150
+ if (v && !out.has(k))
151
+ out.set(k, v);
152
+ }
153
+ const q = out.toString();
154
+ return q ? `${path}?${q}` : path;
126
155
  }
127
156
  /**
128
157
  * The `?next=` a sign-in page was opened with, when it is an address on this
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/rooms",
3
- "version": "0.1.47",
3
+ "version": "0.1.48",
4
4
  "description": "The workspace rooms — Home, Chat, Inbox, Contacts, Meet, Cal, Drive, Board, Work, Bots — and the frame that holds them, once, for every Hanzo surface.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",