Skip to content

Add initial components and dependencies for the GA4 ecommerce demo#824

Merged
ikuleshov merged 16 commits intogoogleanalytics:mainfrom
ikuleshov:main
Feb 18, 2022
Merged

Add initial components and dependencies for the GA4 ecommerce demo#824
ikuleshov merged 16 commits intogoogleanalytics:mainfrom
ikuleshov:main

Conversation

@ikuleshov
Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread gatsby-browser.js
import * as React from "react"
import {StoreProvider} from "./src/components/ga4/EnhancedEcommerce/store-context"
import CustomLayout from "./gatsby/wrapRootElement.js"
import "./src/styles/ecommerce/variables.css"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not strictly necessary, but it'd probably be better if styling was consistent accross this repo. Currently, the main form of styling is through react mui's useStyles hook (example)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, didn't realize that. Looks like I need to move the css variables to Layout/useStyles.ts ? I'll probably do this in a separate PR then.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Following up in separate PR sgtm.

There are a lot of styling options for mui. I usually recommend doing styles at the ./src/components/index.tsx level. You can define the hook inline, or pull it out to its own file. Kinda just depends on preference. One of the big things to keep in mind with mui styling is you don't have to worry about global namespcing because it generates unique class names based on your definitions. This makes it easier to have local css that is unique to the component it's working on.

Comment thread .eslintignore
@@ -1,5 +1,6 @@
src/images/*
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just to double check, this PR only adds in the components, but no new pages, correct? Just getting the repo to be ready for the demo in the future?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, just trying to keep the size of a PR reasonable.

Comment thread gatsby-browser.js
// Wrap every page using a StoreProvider object used by eCommerce demo.
export const wrapRootElement = ({ element }) => (
<StoreProvider>{element}</StoreProvider>
) No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: I think running prettier & yarn format --fix should clean up newlines, etc.

Comment thread gatsby-browser.js

// Wrap every page using a StoreProvider object used by eCommerce demo.
export const wrapRootElement = ({ element }) => (
<StoreProvider>{element}</StoreProvider>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this store provider actually needed for all pages? My gut is that it'd be better to put this provider at the future src/pages/ecommerce page instead.

Copy link
Copy Markdown
Collaborator Author

@ikuleshov ikuleshov Feb 17, 2022

Choose a reason for hiding this comment

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

Although I agree, I am yet unable to find another way to get the same instance of StoreProvider shared between different pages (e.g. product-index and product-details). If I move StoreProvider from the wrapper to, say, Layout component, each page gets its own instance of StoreProvider which obviously results in the cart being lost once you navigate between pages. I'll try to find a way to limit she scope of StoreProvider to the ecommerce demo only, but have not figured this out yet.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, I see.

If you have actual distinct pages (in ./src/pages/) this would be the only way to do this via useContext. That's probably fine, but another option that might be worth exploring is to manage that state in redux, which is already wired in via here. This isn't a silver bullet either, so I'm happy with whatever decision you come to on the tradeoffs of keeping it in different places.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh one last thing to consider. Since this is already a firebase project, it should be fairly trivial to start using firestore if you want to persist cart data.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

True, but this is really just a demo. If we have an option of not storing any data on the server at all, I'd rather vouch for that...

@ikuleshov ikuleshov merged commit d689cf8 into googleanalytics:main Feb 18, 2022
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