Skip to main content

Page Metadata

The SDK automatically collects page metadata from the DOM on every track() call. By default it reads from application/ld+json structured data embedded in the page.

Default Field Mappings

SDK FieldJSON-LD KeyNotes
page_titleheadline or nameFalls back to document.title if not found
content_type@type
content_ididentifier or @idTries identifier first
publisherpublisher.nameNested object path
object_type@type
object_ididentifier or @idTries identifier first
contextarticleSection

url and referer are always collected automatically from window.location.href and document.referrer.

JSON-LD Examples

NewsArticle

For article pages, include a NewsArticle block with all relevant fields:

<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "NewsArticle",
"headline": "City Council Approves New Housing Plan",
"identifier": "story-12345",
"publisher": {
"@type": "Organization",
"name": "Example News"
},
"articleSection": "Local Government"
}
</script>

WebPage

For non-article pages, use a WebPage block:

<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebPage",
"name": "About Us",
"@id": "https://example.com/about",
"publisher": {
"@type": "Organization",
"name": "Example News"
}
}
</script>

Note that for WebPage, the context field will be null since there is no articleSection.

@graph format

Some SEO plugins (such as Yoast SEO) emit a single JSON-LD block using the @graph format rather than one block per type:

<script type="application/ld+json">
{
"@context": "https://schema.org",
"@graph": [
{
"@type": "NewsArticle",
"headline": "City Council Approves New Housing Plan",
"identifier": "story-12345",
"publisher": { "@type": "Organization", "name": "Example News" },
"articleSection": "Local Government"
},
{
"@type": "WebSite",
"name": "Example News",
"url": "https://example.com/"
}
]
}
</script>

The SDK handles this automatically — it searches within @graph and applies the same type priority to pick the best item.

Type priority: If multiple JSON-LD blocks (or items within @graph) exist on the page, the SDK picks the one with the highest priority: NewsArticle > Article > WebPage > any other type.

Overriding Defaults

Any field mapping can be overridden via the pageData property of window.__allegro, set before client.js loads. This is useful for publishers that use a GTM data layer or other data sources instead of JSON-LD.

Data layer source

Publishers using a GTM data layer (<meta name="gtm-dataLayer" content='{"key":"value"}'>) can map fields like this:

<script>
window.__allegro = {
pageData: {
page_title: { source: 'dataLayer', key: 'gtmStoryTitle' },
content_type: { source: 'dataLayer', key: 'gtmPageType' },
content_id: { source: 'dataLayer', key: 'gtmBspStoryId' },
publisher: { source: 'dataLayer', key: 'gtmSiteName' },
object_type: { source: 'dataLayer', key: 'gtmPageType' },
object_id: { source: 'dataLayer', key: 'gtmBspStoryId' },
context: { source: 'dataLayer', key: 'gtmCategory' },
},
};
</script>
<script src="https://your-allegro-instance.com/client.js"></script>

Meta tag source

Individual fields can also be pulled from <meta> tags:

<script>
window.__allegro = {
pageData: {
content_id: { source: 'meta', key: 'article:id' },
publisher: { source: 'meta', key: 'og:site_name' },
},
};
</script>
<script src="https://your-allegro-instance.com/client.js"></script>

All Source Types

SourceHow it readskey format
jsonLd<script type="application/ld+json">Dot-path like publisher.name; pipe-separated fallbacks like headline|name
meta<meta name="..." content="...">The name attribute value
dataLayer<meta name="gtm-dataLayer" content='...'>Property name in the JSON object
selectorCSS selector → textContentAny valid CSS selector
attributeCSS selector → element attributeselector@attribute e.g. body@data-publisher

Per-Call Overrides

Any field can also be passed directly to track(). Per-call values take precedence over auto-collected page data:

allegro.track('article_read', {
content_id: '12345',
content_type: 'article',
});