Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement webengage #496

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e8375ac
add route for webengage push notification
phaneendraandukuri Feb 1, 2023
ed14f8e
update framework version
phaneendraandukuri Feb 1, 2023
7e4a899
add data in response
phaneendraandukuri Feb 2, 2023
b1abd48
add req.body in console.log
phaneendraandukuri Feb 3, 2023
49dddde
update framework version
phaneendraandukuri Feb 3, 2023
84a4ab5
add script for webengage
phaneendraandukuri Feb 3, 2023
7951dc1
add script in service-worker.js
phaneendraandukuri Feb 5, 2023
4cefbee
revert service-worker.js
phaneendraandukuri Feb 5, 2023
d8fc958
add new service-worker.js in the root directory
phaneendraandukuri Feb 6, 2023
11851c2
move service-worker.js into public folder
phaneendraandukuri Feb 6, 2023
dd3ceca
update framework version
phaneendraandukuri Feb 6, 2023
5930f81
update framework version
phaneendraandukuri Feb 6, 2023
a31fb29
update framework version
phaneendraandukuri Feb 6, 2023
e74d43d
update framework version
phaneendraandukuri Feb 6, 2023
6dfea03
remove toggle for the route
phaneendraandukuri Feb 6, 2023
31e7bcb
modify event api endpoint
phaneendraandukuri Feb 8, 2023
c3775a1
modify event api endpoint
phaneendraandukuri Feb 14, 2023
e073acd
modify webengageApi
phaneendraandukuri Feb 15, 2023
9648fb0
added toggle
phaneendraandukuri Feb 15, 2023
0a89776
add webengage import in service-worker.ejs
phaneendraandukuri Feb 16, 2023
f86c308
remove onesignal configuration
phaneendraandukuri Feb 16, 2023
b98ed1a
remove onesignal configuration
phaneendraandukuri Feb 16, 2023
6839206
remove other lines of code from service-worker.ejs
phaneendraandukuri Feb 16, 2023
9376c00
add webengage setattribute in layout.ejs
phaneendraandukuri Feb 16, 2023
e2c1601
add user_type in the webengage event data
phaneendraandukuri Feb 16, 2023
9899d7f
empty commit
phaneendraandukuri Feb 21, 2023
08b5f92
update framework version
phaneendraandukuri Feb 21, 2023
1fca858
update framework version
phaneendraandukuri Feb 21, 2023
c222022
modify api endpoint route
phaneendraandukuri Feb 22, 2023
f707cca
modify api endpoint route
phaneendraandukuri Feb 22, 2023
fa47dc4
empty commit
phaneendraandukuri Feb 23, 2023
792b089
remove /api from the endpoint
phaneendraandukuri Feb 23, 2023
fa76d78
modify endpoint without /api
phaneendraandukuri Feb 23, 2023
cb1bacb
add variable in layout.ejs
phaneendraandukuri Feb 23, 2023
da66347
separate weengage user attribute in a different file
phaneendraandukuri Mar 29, 2023
4bc4d0c
add support to take custom attributes
phaneendraandukuri Mar 29, 2023
aea8a9f
remove unnecessary console.log
phaneendraandukuri Mar 30, 2023
130a240
pr changes
phaneendraandukuri Mar 30, 2023
b109e40
dummy commit in webengage branch
phaneendraandukuri Mar 30, 2023
35ff375
set we_custom_render attribute in webengage
phaneendraandukuri Mar 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions app/client/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import "../../app/assets/stylesheets/app.scss";
const opts = {
enableServiceWorker: process.env.NODE_ENV === "production",
appVersion: require("../isomorphic/app-version"),
preRenderApplication
preRenderApplication,
};

function enableHotReload(store) {
Expand All @@ -21,12 +21,6 @@ function enableHotReload(store) {
}
}

if (window.OneSignal) {
Object.assign(opts, {
serviceWorkerLocation: "/OneSignalSDKWorker.js"
});
}

global.wretch = wretch;

startApp(renderApplication, REDUCERS, opts).then(enableHotReload);
64 changes: 36 additions & 28 deletions app/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,64 @@ import {
isomorphicRoutes,
staticRoutes,
ampRoutes,
getWithConfig
getWithConfig,
} from "@quintype/framework/server/routes";
import { generateRoutes, STATIC_ROUTES } from "./routes";
import { renderLayout } from "./handlers/render-layout";
import { loadData, loadErrorData } from "./load-data";
import { pickComponent } from "../isomorphic/pick-component";
import { generateStaticData, generateStructuredData, SEO } from "@quintype/seo";
import webengageConfig from "../../config/webengage-config";

export const app = createApp();

upstreamQuintypeRoutes(app, {});

const redirectCollectionHandler = () => async (req, res, next, { client, config }) => {
const response = await Collection.getCollectionBySlug(client, req.params.collectionSlug, { limit: 20 }, { depth: 2 });
if (!response) {
return next();
}
const collection = response && response.collection;
if (collection.template === "section") {
const sectionId = collection.metadata.section[0].id;
const section = config.sections.find(section => section.id === sectionId) || {};
return res.redirect(301, `${section["section-url"]}`);
}
const redirectCollectionHandler =
() =>
async (req, res, next, { client, config }) => {
const response = await Collection.getCollectionBySlug(
client,
req.params.collectionSlug,
{ limit: 20 },
{ depth: 2 }
);
if (!response) {
return next();
}
const collection = response && response.collection;
if (collection.template === "section") {
const sectionId = collection.metadata.section[0].id;
const section = config.sections.find((section) => section.id === sectionId) || {};
return res.redirect(301, `${section["section-url"]}`);
}

if (collection.template === "author") {
return res.redirect(301, `/author/${req.params.collectionSlug}`);
}
return next();
};
if (collection.template === "author") {
return res.redirect(301, `/author/${req.params.collectionSlug}`);
}
return next();
};

const logError = error => logger.error(error);
const logError = (error) => logger.error(error);

getWithConfig(app, "/collection/:collectionSlug", redirectCollectionHandler(), {
logError
logError,
});

function returnConfig(req) {
return getClient(req.hostname)
.getConfig()
.then(res => res.config || []);
.then((res) => res.config || []);
}

app.get("*", (req, res, next) => {
if (req.hostname.includes("auth")) {
const whitelistedUrls = ["user-login", "route-data.json", "manifest.json"];
const isPathPresent = element => req.params[0].includes(element);
const isPathPresent = (element) => req.params[0].includes(element);
if (whitelistedUrls.some(isPathPresent)) {
return next();
} else {
returnConfig(req).then(response => {
returnConfig(req).then((response) => {
const sketchesHost = response["sketches-host"];
res.redirect(301, sketchesHost);
});
Expand All @@ -72,21 +80,21 @@ function generateSeo(config, pageType) {
structuredData: Object.assign(generateStructuredData(config), {
enableLiveBlog: true,
enableVideo: true,
enableNewsArticle: true
enableNewsArticle: true,
}),
enableTwitterCards: true,
enableOgTags: true,
enableNews: true
enableNews: true,
});
}

ampRoutes(app, {
seo: generateSeo
seo: generateSeo,
});

isomorphicRoutes(app, {
appVersion: require("../isomorphic/app-version"),
logError: error => logger.error(error),
logError: (error) => logger.error(error),
generateRoutes: generateRoutes,
loadData: loadData,
pickComponent: pickComponent,
Expand All @@ -96,6 +104,6 @@ isomorphicRoutes(app, {
staticRoutes: STATIC_ROUTES,
seo: generateSeo,
preloadJs: true,
oneSignalServiceWorkers: true,
prerenderServiceUrl: "https://prerender.quintype.io"
prerenderServiceUrl: "https://prerender.quintype.io",
webengageConfig,
});
19 changes: 6 additions & 13 deletions app/server/handlers/render-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,9 @@ const fontJsContent = assetPath("font.js") ? readAsset("font.js") : "";
const allChunks = getAllChunks("list", "story", "home");

export async function renderLayout(res, params) {
const {
gtmId,
gaId,
cdnImage,
isOnesignalEnable,
isGtmEnable,
isGaEnable,
enableAds,
loadAdsSynchronously,
pageType,
} = getConfig(params.store.getState());
const { gtmId, gaId, cdnImage, isGtmEnable, isGaEnable, enableAds, loadAdsSynchronously, pageType } = getConfig(
params.store.getState()
);
const chunk = params.shell ? null : allChunks[getChunkName(params.pageType)];
const criticalCss = await getCriticalCss();
const styleTags = await getStyleTags();
Expand All @@ -38,6 +30,8 @@ export async function renderLayout(res, params) {
get(params.store.getState(), ["qt", "config", "publisher-attributes", "placeholder_delay"])
);

const webengageLicenseCode = get(params.store.getState(), ["qt", "config", "webengage-config", "licenseCode"], "");

res.render(
"pages/layout",
Object.assign(
Expand Down Expand Up @@ -72,13 +66,12 @@ export async function renderLayout(res, params) {
serialize,
isGtmEnable,
isGaEnable,
isOnesignalEnable,
oneSignalScript: params.oneSignalScript,
enableAds: enableAds && params.pageType !== "profile-page",
loadAdsSynchronously,
placeholderDelay,
pageType,
enableBreakingNews: params.pageType !== "profile-page",
webengageLicenseCode,
},
params
)
Expand Down
1 change: 0 additions & 1 deletion app/server/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ export const getConfig = (state) => {
gaId: get(state, ["qt", "config", "publisher-attributes", "google_analytics", "id"], ""),
isGaEnable: get(state, ["qt", "config", "publisher-attributes", "google_analytics", "is_enable"], false),
cdnImage: get(state, ["qt", "config", "cdn-image"], ""),
isOnesignalEnable: get(state, ["qt", "config", "publisher-attributes", "onesignal", "is_enable"], false),
enableAds: get(state, ["qt", "config", "ads-config", "dfp_ads", "enable_ads"]),
loadAdsSynchronously: get(state, ["qt", "config", "ads-config", "dfp_ads", "load_ads_synchronously"]),
pageType: get(state, ["qt", "pageType"], ""),
Expand Down
21 changes: 12 additions & 9 deletions app/server/load-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { getNavigationMenuArray } from "./data-loaders/menu-data";
import { loadCollectionPageData } from "./data-loaders/collection-page-data";
import { loadAuthorPageData } from "./data-loaders/author-page-data";
import { PAGE_TYPE } from "../isomorphic/constants";
import webengageConfig from "../../config/webengage-config";

const { ads } = require("@quintype/framework/server/static-configuration");

Expand All @@ -27,10 +28,10 @@ const WHITELIST_CONFIG_KEYS = [
"publisher-name",
"public-integrations",
"sketches-host",
"publisher-settings"
"publisher-settings",
];

const svgSpritePath = Array.from(getAssetFiles()).find(asset => asset.includes("sprite"));
const svgSpritePath = Array.from(getAssetFiles()).find((asset) => asset.includes("sprite"));

export function getPublisherAttributes(publisherYml = publisher) {
const publisherAttributes = get(publisherYml, ["publisher"], {});
Expand All @@ -42,15 +43,16 @@ export function loadErrorData(error, config) {
const errorComponents = { 404: "not-found" };
return Promise.resolve({
data: {
navigationMenu: getNavigationMenuArray(config.layout.menu, config.sections)
navigationMenu: getNavigationMenuArray(config.layout.menu, config.sections),
},
config: Object.assign(pick(config.asJson(), WHITELIST_CONFIG_KEYS), {
"publisher-attributes": publisherAttributes,
"webengage-config": webengageConfig,
"ads-config": ads,
svgSpritePath
svgSpritePath,
}),
pageType: errorComponents[error.httpStatusCode],
httpStatusCode: error.httpStatusCode || 500
httpStatusCode: error.httpStatusCode || 500,
});
}

Expand Down Expand Up @@ -89,22 +91,23 @@ export function loadData(pageType, params, config, client, { host, next, domainS
}
}

return _loadData().then(data => {
return _loadData().then((data) => {
return {
httpStatusCode: data.httpStatusCode || 200,
pageType: data.pageType || pageType,
data: Object.assign({}, data, {
navigationMenu: getNavigationMenuArray(config.layout.menu, config.sections),
timezone: publisherAttributes.timezone || null
timezone: publisherAttributes.timezone || null,
}),
config: Object.assign(pick(config.asJson(), WHITELIST_CONFIG_KEYS), {
"publisher-attributes": publisherAttributes,
"webengage-config": webengageConfig,
"image-cdn-format": "gumlet",
"ads-config": ads,
svgSpritePath,
domainSlug,
showPlaceholder: publisherAttributes.enable_placeholder
})
showPlaceholder: publisherAttributes.enable_placeholder,
}),
};
});
}
5 changes: 5 additions & 0 deletions config/webengage-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
enableWebengage: true,
licenseCode: "~10a5cb515",
apiKey: "2bdc2d5d-583f-4937-bd5a-4dff207a59c3",
};
Loading