Skip to content

Commit

Permalink
Merge pull request #6 from solocommand/braze-liquid-vars
Browse files Browse the repository at this point in the history
Add Braze External ID tracking to links
jwade1327 authored Nov 22, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 6fb0741 + 95ec14b commit 574d4a8
Showing 10 changed files with 61 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { get, getAsObject } from "@parameter1/base-cms-object-path";
import buildLinkUrl from '@science-medicine-group/package-common/utils/build-link-url';

$ const { req } = out.global;
$ const nativeAdLayout = get(req, "query.native-ad-layout");
$ const newsletter = getAsObject(input, "newsletter");
$ const { sectionName, date, content, linkLabelProps } = input;
$ const { adLocation, platformDesignator } = linkLabelProps;

$ const url = get(content, "siteContext.path");
$ const url = buildLinkUrl(get(content, "siteContext.path"));
$ const company = getAsObject(content, "company");
$ const label = input.label || "Paid Advertisement";

Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { get, getAsObject } from "@parameter1/base-cms-object-path";
import buildLinkUrl from '@science-medicine-group/package-common/utils/build-link-url';

$ const newsletter = getAsObject(input, "newsletter");
$ const { sectionName, date, content, linkLabelProps } = input;
$ const { adLocation, platformDesignator } = linkLabelProps;

$ const url = get(content, "siteContext.path");
$ const url = buildLinkUrl(get(content, "siteContext.url"));
$ const company = getAsObject(content, "company");

$ const linkLabel = `ad|${adLocation}|${platformDesignator}|${company.name}|${content.name}`;
@@ -52,7 +53,7 @@ $ const imgLinkStyles = {
options={ w: 180, h: 80, fit: "fill", auto: "format,compress" }
attrs={ border: 0, width: 90, style: imgStyles }
>
<@link href=content.siteContext.url target="_blank" attrs={ style: imgLinkStyles } />
<@link href=url target="_blank" attrs={ style: imgLinkStyles } />
</marko-newsletter-imgix>
</marko-core-obj-value>
</td>
5 changes: 3 additions & 2 deletions packages/common/components/blocks/content/background.marko
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { get, getAsObject } from "@parameter1/base-cms-object-path";
import defaultValue from "@parameter1/base-cms-marko-core/utils/default-value";
import queryFragment from "@science-medicine-group/package-common/graphql/fragments/content-list";
import buildLinkUrl from '@science-medicine-group/package-common/utils/build-link-url';

$ const newsletter = getAsObject(input, "newsletter");
$ const { sectionName, date } = input;
@@ -54,7 +55,7 @@ $ const imgLinkStyles = {
class="img_resize1"
attrs={ border: 0, width: 580, align: "center", vspace: 5, style: imgStyles }
>
<@link href=content.siteContext.url target="_blank" attrs={ style: imgLinkStyles } />
<@link href=buildLinkUrl(content.siteContext.url) target="_blank" attrs={ style: imgLinkStyles } />
</marko-newsletter-imgix>
</marko-core-obj-value>
</td>
@@ -75,7 +76,7 @@ $ const imgLinkStyles = {
</tr>
<tr>
<td align="left" valign="top">
<a href=content.linkUrl style="font-size: 18px;line-height: 23px;color: #055c9d;font-family: 'Roboto', Arial, sans-serif;padding: 0 15px;text-decoration: none;" target="_blank">
<a href=buildLinkUrl(content.linkUrl) style="font-size: 18px;line-height: 23px;color: #055c9d;font-family: 'Roboto', Arial, sans-serif;padding: 0 15px;text-decoration: none;" target="_blank">
${content.linkText}
</a>
</td>
20 changes: 10 additions & 10 deletions packages/common/components/blocks/content/list-item.marko
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { get, getAsArray } from "@parameter1/base-cms-object-path";
import defaultValue from "@parameter1/base-cms-marko-core/utils/default-value";
import { URLSearchParams } from "url";

$ const { content, urlParams, ctaLinkStyle } = input;
import buildLinkUrl from '@science-medicine-group/package-common/utils/build-link-url';

$ const { content, ctaLinkStyle } = input;
$ const url = buildLinkUrl(content.siteContext.url);
$ const withImage = defaultValue(input.withImage, true);
$ const imagePosition = defaultValue(input.imagePosition, 'right');
$ const withSection = defaultValue(input.withSection, false);
@@ -71,7 +71,7 @@ $ const linkLabel = input.storyLocation ? `story|${input.storyLocation}|${conten
class="img_resize1"
attrs={ border: 0, width: 610, align: "center", vspace: 5, style: imgStyles }
>
<@link href=content.siteContext.url target="_blank" attrs={ style: imgLinkStyles, linklabel: linkLabel } />
<@link href=url target="_blank" attrs={ style: imgLinkStyles, linklabel: linkLabel } />
</marko-newsletter-imgix>
</marko-core-obj-value>
</td>
@@ -88,7 +88,7 @@ $ const linkLabel = input.storyLocation ? `story|${input.storyLocation}|${conten
<table role="presentation" width="100%" border="0" cellpadding="0" cellspacing="0" class="pad" style="padding: 0 30px 0px 0;">
<tr>
<td align="left" valign="top">
<a style="font-family: 'Roboto', arial, sans-serif;font-size: 24px;line-height: 28px;color: #202022;font-weight: 700;text-decoration: none;" class="font1" href=content.siteContext.url linklabel=linkLabel>
<a style="font-family: 'Roboto', arial, sans-serif;font-size: 24px;line-height: 28px;color: #202022;font-weight: 700;text-decoration: none;" class="font1" href=url linklabel=linkLabel>
$!{content.name}
</a>
</td>
@@ -105,7 +105,7 @@ $ const linkLabel = input.storyLocation ? `story|${input.storyLocation}|${conten
<if(continueReading === true)>
<common-table-spacer-element height="9" />
$ const linkText = content.linkText || undefined;
<common-cta-element link-style=ctaLinkStyle link-text=linkText link-url=content.siteContext.url link-label=linkLabel />
<common-cta-element link-style=ctaLinkStyle link-text=linkText link-url=url link-label=linkLabel />
</if>
</table>
</td>
@@ -121,7 +121,7 @@ $ const linkLabel = input.storyLocation ? `story|${input.storyLocation}|${conten
class="img_resize2"
attrs={ border: 0, width: 200, height: 133, style: imgStyles }
>
<@link href=content.siteContext.url target="_blank" attrs={ style: imgLinkStyles, linklabel: linkLabel } />
<@link href=url target="_blank" attrs={ style: imgLinkStyles, linklabel: linkLabel } />
</marko-newsletter-imgix>
</marko-core-obj-value>
</td>
@@ -141,7 +141,7 @@ $ const linkLabel = input.storyLocation ? `story|${input.storyLocation}|${conten
<if(continueReading === true)>
<common-table-spacer-element height="9" />
$ const linkText = content.linkText || undefined;
<common-cta-element link-style=ctaLinkStyle link-text=linkText link-url=content.siteContext.url link-label=linkLabel />
<common-cta-element link-style=ctaLinkStyle link-text=linkText link-url=url link-label=linkLabel />
</if>
</table>
</td>
@@ -150,7 +150,7 @@ $ const linkLabel = input.storyLocation ? `story|${input.storyLocation}|${conten
<else>
<tr>
<td align="left" valign="top">
<a style="font-family: 'Roboto', arial, sans-serif;font-size: 24px;line-height: 28px;color: #202022;font-weight: 700;text-decoration: none;" href=content.siteContext.url linklabel=linkLabel>
<a style="font-family: 'Roboto', arial, sans-serif;font-size: 24px;line-height: 28px;color: #202022;font-weight: 700;text-decoration: none;" href=url linklabel=linkLabel>
$!{content.name}
</a>
</td>
@@ -164,7 +164,7 @@ $ const linkLabel = input.storyLocation ? `story|${input.storyLocation}|${conten
<if(continueReading === true)>
<common-table-spacer-element height="9" />
$ const linkText = content.linkText || undefined;
<common-cta-element link-style=ctaLinkStyle link-text=linkText link-url=content.siteContext.url link-label=linkLabel />
<common-cta-element link-style=ctaLinkStyle link-text=linkText link-url=url link-label=linkLabel />
</if>
</else>
<common-table-spacer-element height="32" />
10 changes: 8 additions & 2 deletions packages/common/components/blocks/footer.marko
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { get, getAsObject, getAsArray } from "@parameter1/base-cms-object-path";
import defaultValue from "@parameter1/base-cms-marko-core/utils/default-value";
import buildLinkUrl from '@science-medicine-group/package-common/utils/build-link-url';

$ const { website, config } = out.global;
$ const { newsletter } = input;
@@ -10,6 +11,11 @@ $ const subscribeLink = get(newsletterConfig, "subscribeLink");
$ const publicationName = website.get("name");
$ const footerWidth = defaultValue(get(newsletterConfig, "logo.footerWidth"), 130);

$ const preferenceCenterUrl = buildLinkUrl(
get(newsletterConfig, "preferenceCenter"),
{ email: '{{${email_address}}}' }
);

$ const standardStyle = {
"font-size": "17px",
"line-height": "22px",
@@ -136,7 +142,7 @@ $ const stealthLinkStyle = {
<tr>
<td align="left" valign="top" style=standardStyle>
<for|link, index| of=contactLinks>
<a href=link.href style=standardUnderlineStyle>
<a href=buildLinkUrl(link.href) style=standardUnderlineStyle>
${link.label}
</a>
<if(index < (contactLinks.length - 1))>
@@ -150,7 +156,7 @@ $ const stealthLinkStyle = {

<tr>
<td align="left" valign="top" style=standardStyle>
You are receiving this email because you subscribed to receive relevant news from ${publicationName}. To update your email subscriptions, visit the LabPulse <a href=get(newsletterConfig, "preferenceCenter") style=linkStyle>preference center</a>.
You are receiving this email because you subscribed to receive relevant news from ${publicationName}. To update your email subscriptions, visit the LabPulse <a href=preferenceCenterUrl style=linkStyle>preference center</a>.
</td>
</tr>
<common-table-spacer-element height="19" />
5 changes: 3 additions & 2 deletions packages/common/components/blocks/view-online.marko
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import buildLinkUrl from '@science-medicine-group/package-common/utils/build-link-url';

$ const { website } = out.global;

<tr>
@@ -7,8 +9,7 @@ $ const { website } = out.global;
<common-table-spacer-element height="13" />
<tr>
<td align="center" valign="middle" style="font-size:15px;line-height:19px; color:#62626c;font-weight:400;">
<!-- <a href="@{mv_online_version}@" style="text-decoration: none;color: #62626c;">View in browser</a> &nbsp; | &nbsp; -->
<a href=website.get("origin") style="text-decoration: none;color: #62626c;">${website.get("name")}</a>
<a href=buildLinkUrl(website.get("origin")) style="text-decoration: none;color: #62626c;">${website.get("name")}</a>
</td>
</tr>
<common-table-spacer-element height="10" />
4 changes: 3 additions & 1 deletion packages/common/components/elements/link.marko
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import buildLinkUrl from '@science-medicine-group/package-common/utils/build-link-url';

$ const { linkText, linkUrl, linkLabel } = input;

$ const linkStyle = {
@@ -11,7 +13,7 @@ $ const linkStyle = {

<tr>
<td align="left" valign="top">
<a style=linkStyle href=linkUrl linklabel=linkLabel>
<a style=linkStyle href=buildLinkUrl(linkUrl) linklabel=linkLabel>
${linkText}
</a>
</td>
4 changes: 3 additions & 1 deletion packages/common/components/elements/logo.marko
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import defaultValue from "@parameter1/base-cms-marko-core/utils/default-value";
import buildLinkUrl from '@science-medicine-group/package-common/utils/build-link-url';

$ const { website, config } = out.global;
$ const { newsletter, width } = input;

$ const url = buildLinkUrl(website.get("origin"));
$ const newsletterConfig = config.get(newsletter.alias);

$ const logoSrc = newsletterConfig.logo.src;
@@ -30,5 +32,5 @@ $ const attrs = {
}

<marko-newsletter-imgix src=logoSrc options=options alt=alt attrs=attrs options={ fit: "fill", fillColor: "#ffffff" }>
<@link href=website.get("origin") attrs={ style: linkStyles } target="_blank" />
<@link href=url attrs={ style: linkStyles } target="_blank" />
</marko-newsletter-imgix>
25 changes: 25 additions & 0 deletions packages/common/utils/build-link-url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* eslint-disable no-template-curly-in-string */
const liquidVar = /{{.*?}}/;
const isObj = v => typeof v === 'object';

const alwaysAppend = {
braze_int_id: '{{${braze_id}}}',
braze_ext_id: '{{${user_id}}}',
};

module.exports = (href, params = {}) => {
const url = new URL(href);
const toAppend = { ...(isObj(params) && { ...params }), ...alwaysAppend };

// Set append the values to the URL
Object.entries(toAppend).forEach(([key, value]) => { url.searchParams.set(key, value); });

let encoded = `${url}`;
// Decode any liquid tags to ensure successful replacement.
Object.entries(toAppend).forEach(([, value]) => {
if (liquidVar.test(value)) {
encoded = encoded.replace(encodeURIComponent(value), decodeURIComponent(value));
}
});
return encoded;
};
2 changes: 1 addition & 1 deletion tenants/all/config/core.js
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ const config = {
'letter-from-the-editor': {
...brands.labPulse,
name: 'Letter From The Editor',
preferenceCenter: 'https://www.labpulse.com/user/subscribe?email=%7b%7b%24%7bemail_address%7d%7d%7d',
preferenceCenter: 'https://www.labpulse.com/user/subscribe',
},
};

0 comments on commit 574d4a8

Please sign in to comment.