Skip to content

(demo-store): Improve Shopify analytics implementation#666

Closed
juanpprieto wants to merge 3 commits into
2023-01from
analytics-payload
Closed

(demo-store): Improve Shopify analytics implementation#666
juanpprieto wants to merge 3 commits into
2023-01from
analytics-payload

Conversation

@juanpprieto
Copy link
Copy Markdown
Contributor

@juanpprieto juanpprieto commented Mar 10, 2023

WHY are these changes introduced?

Improve the demo store Shopify analytics implementation by ensuring all applicable routes return analytics metadata in the loader.

This PR creates better synergy between seo and anlytics with a payload helper. For more info see the seo PR.

WHAT is this pull request doing?

  • Adds a new lib utility analyticsPayload to help manage shopify analytics payloads in a centralized location ~/libs/analytics.server.ts

analyticsPayload helper

// ~/libs/analytics.server.ts
export const analyticsPayload = {
  article,
  blog,
  cart,
  collection,
  home,
  listCollections,
  page,
  policies,
  policy,
  product,
  root,
};

Example implementation product route

// ~/routes/products/$productHandle.tsx
import {analyticsPayload} from '~/libs/analytics.server';

export async function loader({request}) {
  // ... 
  const analytics = analyticsPayload.product({
    product,
    selectedVariant,
  });
  return {product, analytics}
}

similar helper for all other routes...

// ~/routes/collections/$collectionHandle.tsx
import {analyticsPayload} from '~/libs/analytics.server';

export async function loader({request}) {
  // ... 
  const analytics = analyticsPayload.collection({collection});
  return {collection, analytics}
}

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes
  • I've added or updated the documentation

@juanpprieto juanpprieto requested a review from a team March 10, 2023 00:07
Copy link
Copy Markdown

@wizardlyhel wizardlyhel left a comment

Choose a reason for hiding this comment

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

Let's hold this for now. I do like the cleanness in the route but I also would also want the demo store implementation be reflected in developer docs.

@frehner
Copy link
Copy Markdown
Contributor

frehner commented Apr 26, 2023

Closing, but if you feel like this is still applicable please reopen and resolve conflicts! 👍

@frehner frehner closed this Apr 26, 2023
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.

4 participants