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

feat: add martech plugin to connect to analytics and target #153

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

ramboz
Copy link

@ramboz ramboz commented Jul 20, 2024

This PR adds integration with Target, Launch & ACDL via the martech library. It also moves the Analytics instrumentation to the martech library, and creates a more generic loader to combine the GTM and WebSDK logic and isolate it from the main scripts.js file.

At a high level:

  • lib-analytics.js is renamed to lib-martech-loaded.js
    • inline scripts are changed to direct execution to avoid HTML parsing
    • consent is updated to v2 API
    • conversion, GTM, alloy and click trackings are all moved to the martech loader
    • launch and analytics envs will be mapped as follows:
      • *.petwatch.com => prod
      • *.live / *.page urls => stage
      • everything else => dev
    • a new trackAnalyticsEvent method is exported to specifically track events in Analytics instead of GTM
    • updates alloy.js to v2.21.1
  • Adobe martech library is add as plugins/martech
  • head.html gets new preload/preconnect links for resources immediately imported, so we don't have to wait for scripts.js to be parsed.

Test URLs:

Copy link

aem-code-sync bot commented Jul 20, 2024

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch and validate page speed.
In case there are problems, just click a checkbox below to rerun the respective action.

  • Re-run PSI checks
  • Re-sync branch
Commits

Copy link

aem-code-sync bot commented Jul 20, 2024

Page Scores Audits Google
📱 / PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI
🖥️ / PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI

@ramboz
Copy link
Author

ramboz commented Jul 20, 2024

@fe-lix- @ekremney @bohnertchris Since I did quite some heavy lib-analytics.js refactoring for this, if you know the various analytics events they were tracking before, could you perform a quick sanity check to make sure we didn't lose anything along the way?

@ekremney
Copy link
Collaborator

@ramboz it has been almost 1 year since the custom analytics events were implemented for this project. I am afraid I cannot recall all the details. The most important events were tracked by GA4 via trackGTMEvent

@@ -246,123 +245,15 @@ async function loadEager(doc) {

const main = doc.querySelector('main');
if (main) {
createInlineScript(document, document.body, getAlloyInitScript(), 'text/javascript');
Copy link
Author

Choose a reason for hiding this comment

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

Handled by the martech lib

@@ -246,123 +245,15 @@ async function loadEager(doc) {

const main = doc.querySelector('main');
if (main) {
createInlineScript(document, document.body, getAlloyInitScript(), 'text/javascript');
createInlineScript(document, document.body, getGTMInitScript(), 'text/javascript');
Copy link
Author

Choose a reason for hiding this comment

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

Moved to the martech loader script

}
}

async function initializeConversionTracking() {
Copy link
Author

Choose a reason for hiding this comment

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

Moved to the martech loader script

sampleRUM('lazy');
sampleRUM.observe(main.querySelectorAll('div[data-block-name]'));
sampleRUM.observe(main.querySelectorAll('picture > img'));

await setupAnalyticsTrackingWithAlloy(document);
Copy link
Author

Choose a reason for hiding this comment

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

Handled by the martech lib

sampleRUM('lazy');
sampleRUM.observe(main.querySelectorAll('div[data-block-name]'));
sampleRUM.observe(main.querySelectorAll('picture > img'));

await setupAnalyticsTrackingWithAlloy(document);
await setupAnalyticsTrackingWithGTM();
Copy link
Author

Choose a reason for hiding this comment

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

Moved to matech loader script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants