Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 24 additions & 2 deletions packages/storefront-events-collector/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ import { configure, hasConfig, setConsent, setExistingAlloy } from "./alloy";
import { subscribeToEvents } from "./events";
import { configureSnowplow } from "./snowplow";

// Snowplow configuration constants
const SNOWPLOW_CONFIG = {
production: {
collectorUrl: "https://commerce.adobedc.net",
collectorPath: "/collector/tp2",
},
qa: {
collectorUrl: "https://com-magento-qa1.collector.snplow.net",
collectorPath: "/com.snowplowanalytics.snowplow/tp2",
},
Comment on lines +10 to +17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be certain - it is OK to expose the QA urls to the public?

One way to protect would be to have the initialization happen at runtime, and use a default value (prod url) or allow passing a collector url/path as argument to override. Then for QA you can intentionally set this in the integration code, without exposing the potentially secret/private QA endpoint.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The qa urls have always been exposed in the webpack configs, so they probably won't be that big of a deal, but this change is going to have unintended consequences for magento users

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll mark this as a draft PR until we meet on Monday and decide next steps. Thanks for reviewing so quick! 🙏🏼

};

/**
* this is the script added to an external build if a user is adding a custom name
* see https://experienceleague.adobe.com/docs/experience-platform/edge/fundamentals/installing-the-sdk.html?lang=en
Expand Down Expand Up @@ -73,15 +85,25 @@ const initializeAlloy = async () => {
const initialize = async () => {
const { context } = window.magentoStorefrontEvents;
const eventForwarding = context.getEventForwarding();
const storefrontInstance = context.getStorefrontInstance();

const sendToSnowplow = eventForwarding?.commerce === false ? false : true;
const sendToAEP = eventForwarding?.aep && hasConfig() ? true : false;

if (sendToSnowplow) {
// Dynamic Snowplow routing based on environment
const environment = storefrontInstance?.environment?.toLowerCase() || "production";
const isQAEnvironment =
environment.includes("stage") || environment.includes("qa") || environment.includes("test");

const config = isQAEnvironment ? SNOWPLOW_CONFIG.qa : SNOWPLOW_CONFIG.production;
const collectorUrl = config.collectorUrl;
const collectorPath = config.collectorPath;

configureSnowplow({
appId: "magento-storefront-event-collector",
collectorUrl: SNOWPLOW_COLLECTOR_URL,
collectorPath: SNOWPLOW_COLLECTOR_PATH,
collectorUrl,
collectorPath,
});
}

Expand Down
3 changes: 0 additions & 3 deletions packages/storefront-events-collector/src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import { MagentoStorefrontEvents } from "@adobe/magento-storefront-events-sdk";
import { AlloyInstance } from "../aep/types";

declare global {
const SNOWPLOW_COLLECTOR_URL: string;
const SNOWPLOW_COLLECTOR_PATH: string;

interface Window {
__alloyNS: string[];
magentoStorefrontEvents: MagentoStorefrontEvents;
Expand Down
7 changes: 0 additions & 7 deletions packages/storefront-events-collector/webpack.dev.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
const webpack = require("webpack");
const { merge } = require("webpack-merge");
const common = require("./webpack.common.js");

module.exports = merge(common, {
mode: "development",
devtool: "eval-source-map",
plugins: [
new webpack.DefinePlugin({
SNOWPLOW_COLLECTOR_URL: JSON.stringify("https://com-magento-qa1.collector.snplow.net"),
SNOWPLOW_COLLECTOR_PATH: JSON.stringify("/com.snowplowanalytics.snowplow/tp2"),
}),
],
});
7 changes: 0 additions & 7 deletions packages/storefront-events-collector/webpack.prod.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
const webpack = require("webpack");
const { merge } = require("webpack-merge");
const common = require("./webpack.common.js");

module.exports = merge(common, {
mode: "production",
plugins: [
new webpack.DefinePlugin({
SNOWPLOW_COLLECTOR_URL: JSON.stringify("https://commerce.adobedc.net"),
SNOWPLOW_COLLECTOR_PATH: JSON.stringify("/collector/tp2"),
}),
],
});
7 changes: 0 additions & 7 deletions packages/storefront-events-collector/webpack.qa.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
const webpack = require("webpack");
const { merge } = require("webpack-merge");
const common = require("./webpack.common.js");

module.exports = merge(common, {
mode: "development",
devtool: "eval-source-map",
plugins: [
new webpack.DefinePlugin({
SNOWPLOW_COLLECTOR_URL: JSON.stringify("https://com-magento-qa1.collector.snplow.net"),
SNOWPLOW_COLLECTOR_PATH: JSON.stringify("/com.snowplowanalytics.snowplow/tp2"),
}),
],
});