@escape-game-over/atlas 0.1.44 → 0.1.46
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/package.json +1 -1
- package/src/analytics/google.ts +33 -25
- package/src/jsonld/organization.ts +17 -1
package/package.json
CHANGED
package/src/analytics/google.ts
CHANGED
|
@@ -345,7 +345,7 @@ export function googleEmits(
|
|
|
345
345
|
}
|
|
346
346
|
|
|
347
347
|
/**
|
|
348
|
-
* Google's tags: a connection and one inline block
|
|
348
|
+
* Google's tags: a connection and one inline block in the head,
|
|
349
349
|
* Tag Manager's `<noscript>` fallback in the body.
|
|
350
350
|
*
|
|
351
351
|
* One block rather than several because `dataLayer` is a queue — consent, the
|
|
@@ -424,6 +424,7 @@ export function googleScripts(
|
|
|
424
424
|
: "",
|
|
425
425
|
tags.length > 0 ? "gtag('js',new Date());" : "",
|
|
426
426
|
...tags.map((id) => `gtag('config',${literal(id)});`),
|
|
427
|
+
loader(tags[0]),
|
|
427
428
|
// Tag Manager's own loader, once per container. It appends its script
|
|
428
429
|
// itself, so it runs after the consent calls already queued above.
|
|
429
430
|
...containers.map(
|
|
@@ -432,35 +433,14 @@ export function googleScripts(
|
|
|
432
433
|
),
|
|
433
434
|
].join("");
|
|
434
435
|
|
|
435
|
-
// The library is fetched once, for the first id, and every id gets its own
|
|
436
|
-
// `config` above. That is Google's documented arrangement rather than a
|
|
437
|
-
// shortcut: *"A single Google tag can have multiple tag IDs"*, and their
|
|
438
|
-
// own example loads `gtag/js?id=G-XXXXXX` once and then configures
|
|
439
|
-
// `GT-XXXXXX` and `DC-ZZZZZZ` against it. The `?id=` only bootstraps the
|
|
440
|
-
// library; the `config` calls are what register a destination.
|
|
441
|
-
//
|
|
442
|
-
// Loading it per id would fetch the same script several times and re-run
|
|
443
|
-
// its bootstrap — more bytes for nothing, and a second copy of a global.
|
|
444
|
-
//
|
|
445
|
-
// <https://developers.google.com/tag-platform/gtagjs/configure>
|
|
446
|
-
const first = tags[0];
|
|
447
436
|
return {
|
|
448
437
|
head: [
|
|
449
438
|
// Ahead of the inline block, which is the only position that buys
|
|
450
|
-
// anything:
|
|
451
|
-
//
|
|
452
|
-
//
|
|
439
|
+
// anything: both loaders' URLs are written *by* that block, so this
|
|
440
|
+
// is the only mention of the origin the browser can act on before
|
|
441
|
+
// the script has run.
|
|
453
442
|
preconnect(TAG_ORIGIN),
|
|
454
443
|
{ kind: "script", content: inline },
|
|
455
|
-
...(first === undefined
|
|
456
|
-
? []
|
|
457
|
-
: [
|
|
458
|
-
{
|
|
459
|
-
kind: "externalScript" as const,
|
|
460
|
-
src: `${TAG_ORIGIN}/gtag/js?id=${encodeURIComponent(first)}`,
|
|
461
|
-
attrs: {},
|
|
462
|
-
},
|
|
463
|
-
]),
|
|
464
444
|
],
|
|
465
445
|
// One per container, and only for Tag Manager: GA4 has no such
|
|
466
446
|
// fallback, because `gtag.js` is the only way it collects anything.
|
|
@@ -470,3 +450,31 @@ export function googleScripts(
|
|
|
470
450
|
})),
|
|
471
451
|
};
|
|
472
452
|
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* `gtag.js`, appended once the page has loaded.
|
|
456
|
+
*
|
|
457
|
+
* Its parse and first run — including a forced reflow of its own — otherwise
|
|
458
|
+
* compete with the page for the load window. Nothing is lost by waiting:
|
|
459
|
+
* `dataLayer` is a queue, and every call above is replayed when it arrives.
|
|
460
|
+
* What waiting costs is a visitor who leaves before `load`, who is not counted.
|
|
461
|
+
*
|
|
462
|
+
* The library is fetched once, for the first id, and every id gets its own
|
|
463
|
+
* `config` above. That is Google's documented arrangement rather than a
|
|
464
|
+
* shortcut: *"A single Google tag can have multiple tag IDs"*, and their
|
|
465
|
+
* own example loads `gtag/js?id=G-XXXXXX` once and then configures
|
|
466
|
+
* `GT-XXXXXX` and `DC-ZZZZZZ` against it. The `?id=` only bootstraps the
|
|
467
|
+
* library; the `config` calls are what register a destination.
|
|
468
|
+
*
|
|
469
|
+
* Loading it per id would fetch the same script several times and re-run
|
|
470
|
+
* its bootstrap — more bytes for nothing, and a second copy of a global.
|
|
471
|
+
*
|
|
472
|
+
* <https://developers.google.com/tag-platform/gtagjs/configure>
|
|
473
|
+
*/
|
|
474
|
+
function loader(first: string | undefined): string {
|
|
475
|
+
if (first === undefined) return "";
|
|
476
|
+
const src = literal(
|
|
477
|
+
`${TAG_ORIGIN}/gtag/js?id=${encodeURIComponent(first)}`
|
|
478
|
+
);
|
|
479
|
+
return `(function(){function l(){var s=document.createElement('script');s.async=true;s.src=${src};document.head.appendChild(s)}document.readyState==='complete'?l():addEventListener('load',l)})();`;
|
|
480
|
+
}
|
|
@@ -4,7 +4,8 @@ import {
|
|
|
4
4
|
type PhoneNumber,
|
|
5
5
|
type PostalAddress,
|
|
6
6
|
} from "../contact.ts";
|
|
7
|
-
import
|
|
7
|
+
import type { ImageAsset } from "../image.ts";
|
|
8
|
+
import { absoluteUrl, type HttpsUrl, joinUrl, type UrlPath } from "../url.ts";
|
|
8
9
|
import { organizationId } from "./ids.ts";
|
|
9
10
|
import { alternateName, type JsonLdNode } from "./node.ts";
|
|
10
11
|
import { postalAddress } from "./place.ts";
|
|
@@ -45,6 +46,14 @@ export interface OrganizationInput {
|
|
|
45
46
|
* engine keeps, not a page resource it re-fetches.
|
|
46
47
|
*/
|
|
47
48
|
readonly logo?: UrlPath;
|
|
49
|
+
/**
|
|
50
|
+
* Photographs of the company's place, as on `LocalBusinessInput.image`.
|
|
51
|
+
*
|
|
52
|
+
* For the shape `address` below is for: one company at one place, with no
|
|
53
|
+
* venue node. Google reads an organization with an address as a local
|
|
54
|
+
* business and flags a missing image there. A logo is not one.
|
|
55
|
+
*/
|
|
56
|
+
readonly image?: readonly ImageAsset[];
|
|
48
57
|
/**
|
|
49
58
|
* The registered name, where it differs from the trading one.
|
|
50
59
|
*
|
|
@@ -156,6 +165,13 @@ export function organization(brand: OrganizationInput): JsonLdNode {
|
|
|
156
165
|
...(brand.logo === undefined
|
|
157
166
|
? {}
|
|
158
167
|
: { logo: joinUrl(brand.url, brand.logo) }),
|
|
168
|
+
...(brand.image === undefined || brand.image.length === 0
|
|
169
|
+
? {}
|
|
170
|
+
: {
|
|
171
|
+
image: brand.image.map((photo) =>
|
|
172
|
+
absoluteUrl(brand.url, photo.src, "organization photo")
|
|
173
|
+
),
|
|
174
|
+
}),
|
|
159
175
|
...(brand.legalName === undefined
|
|
160
176
|
? {}
|
|
161
177
|
: { legalName: brand.legalName }),
|