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 #801 from brandonbk/nx-story-track
Browse files Browse the repository at this point in the history
Add tenantKey to native-x config
  • Loading branch information
brandonbk authored Sep 26, 2023
2 parents 5e30a1d + 104937e commit e3422f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
15 changes: 14 additions & 1 deletion packages/marko-web-native-x/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ class NativeXConfiguration {
* @param {boolean} [params.enabled=true]
* @param {string} [params.defaultAlias=default]
*/
constructor(uri, { enabled = true, defaultAlias = 'default' } = {}) {
constructor(uri, { enabled = true, defaultAlias = 'default', tenantKey } = {}) {
if (!uri) throw new Error('Unable to configure NativeX: no URI was provided.');
this.uri = uri;
this.enabled = enabled;
this.defaultAlias = defaultAlias;
this.tenantKey = tenantKey;

this.client = createClient(this.getGraphQLUri());
this.placements = {};
Expand Down Expand Up @@ -76,6 +77,18 @@ class NativeXConfiguration {
isEnabled() {
return this.enabled;
}

getTenantKey() {
const { tenantKey } = this;
if (tenantKey) return tenantKey;
const [, key] = this.uri.match(/\/\/(\w+)\.native-x/i);
return key;
}

getEntityFor(type) {
const tenantKey = this.getTenantKey();
return `native-x.${tenantKey}.${type}`;
}
}

module.exports = NativeXConfiguration;
17 changes: 7 additions & 10 deletions packages/marko-web-p1-events/components/track-native-story.marko
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@ import { get } from "@parameter1/base-cms-object-path";
$ const { site } = out.global;
$ const { story } = input;
$ const config = site.getAsObject("p1events");
$ const ns = (type) => {
const [,tenantKey] = site.get('nativeX.uri').match(/\/\/(\w+)\.native-x/i);
return `native-x.${tenantKey}.${type}`;
};
$ const nxConfig = site.get("nativeX");

<if(config.enabled)>
<if(config.enabled && nxConfig && nxConfig.enabled)>
$ const { advertiser } = story;
$ const entity = {
id: story.id,
ns: ns(`story`),
ns: nxConfig.getEntityFor("story"),
name: story.title,
props: { type: 'story', published: get(story, 'publishedAt') },
props: { type: "story", published: get(story, "publishedAt") },
...(advertiser && advertiser.id && {
refs: { advertiser: { id: advertiser.id, ns: ns("advertiser"), name: advertiser.name } },
refs: { advertiser: { id: advertiser.id, ns: nxConfig.getEntityFor("advertiser"), name: advertiser.name } },
}),
};
$ const data = {
action: 'View',
category: 'Content',
action: "View",
category: "Content",
entity,
};
<script>
Expand Down

0 comments on commit e3422f2

Please sign in to comment.