Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #805 from B77Mills/gtmNativeXStory
Browse files Browse the repository at this point in the history
Add compoents/builder for nativeXStory GTM context
  • Loading branch information
brandonbk authored Sep 28, 2023
2 parents 6ddb603 + 059ea2b commit c840d48
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/marko-web-gtm/components/context/marko.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,11 @@
"@id": "string",
"@builder": "function",
"@query-fragment": "expression"
},
"<marko-web-gtm-native-x-story-context>": {
"template": "./native-x-story.marko",
"@type": "string",
"@obj": "object",
"@builder": "function"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { isFunction, warn } from "@parameter1/base-cms-utils";
import { nativeXStoryBuilder } from "../../context";

$ const { req } = out.global;
$ const builder = isFunction(input.builder) ? input.builder : nativeXStoryBuilder;
$ const type = input.type || "content";

$ const context = builder({ type, obj: input.obj, req });
<${input.renderBody} context=context />
2 changes: 2 additions & 0 deletions packages/marko-web-gtm/context/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const websiteSectionBuilder = require('./website-section');
const dynamicPageBuilder = require('./dynamic-page');
const magazineIssueBuilder = require('./magazine-issue');
const magazinePublicationBuilder = require('./magazine-publication');
const nativeXStoryBuilder = require('./native-x-story');

module.exports = {
defaultBuilder,
Expand All @@ -12,4 +13,5 @@ module.exports = {
dynamicPageBuilder,
magazineIssueBuilder,
magazinePublicationBuilder,
nativeXStoryBuilder,
};
37 changes: 37 additions & 0 deletions packages/marko-web-gtm/context/native-x-story.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const { getAsObject, getAsArray, get } = require('@parameter1/base-cms-object-path');
const { asObject } = require('@parameter1/base-cms-utils');
const buildQueryString = require('../utils/build-query-string');

module.exports = ({ type, obj, req }) => {
const content = asObject(obj);
const company = getAsObject(content, 'company');
const section = getAsObject(content, 'primarySection');
const hierarchy = getAsArray(section, 'hierarchy').map((s) => ({
id: s.id,
name: s.name,
alias: s.alias,
}));
return {
page_type: type,
canonical_path: get(content, 'siteContext.path'),
query_string: buildQueryString({ req }),
content: {
id: content.id,
type: content.type,
name: content.name,
published: content.published ? new Date(content.published).toISOString() : undefined,
labels: getAsArray(content, 'labels'),
},
company: {
id: company.id,
name: company.name,
},
section: {
id: section.id,
name: section.name,
alias: section.alias,
fullName: section.fullName,
},
section_hierarchy: hierarchy,
};
};

0 comments on commit c840d48

Please sign in to comment.