@chordcommerce/gatsby-theme-autonomy
, via GitHub Packages.Gatsby themes are plugins that include a gatsby-config.js file and add pre-configured functionality, data sourcing, and/or UI code to Gatsby sites. You can think of Gatsby themes as separate Gatsby sites that can be put together and allow you to split up a larger Gatsby project!
gatsby-theme-autonomy
theme includes the Chord SDK, a set of methods you can import and use in your React components to do things like add items to a cart and check out. The theme also preconfigures your Gatsby site with a number of useful ecommerce features like product feeds and internationalization support.useAnalytics()
useAnalytics
hook returns a series of functions that fire a tracking event to Segment, our integrated analytics platform.@chordcommerce/gatsby-theme-autonomy
theme. However, some events need to be closely tied to the UI, like click tracking. These events are available via the useAnalytics
hook and listed below.trackClickCollection()
trackClickCollection
function fires a Collection Clicked
event to Segment. You should call this function when the user clicks on a link to a collection.trackClickProduct()
trackClickProduct
function fires a Product Clicked
event to Segment. You should call this function when the user clicks on a link to a product.trackCreateStockRequest()
trackCreateStockRequest
function fires a Stock Request Created
event to Segment. You should call this function when a product waitlist form is submitted.trackViewCart()
trackViewCart
function fires a Cart Viewed
event to Segment. You should call this function when the cart page is viewed.trackProductViewed()
trackProductViewed
function fires a Product Viewed
event to Segment. You should call this function when a product page is opened.useAuth()
useAuth
hook returns information about the current authentication session and functions for logging in and logging out. Chord supports passwordless authentication with Magic.isLoggedIn
is a boolean indicating whether the user is currently logged in.isFetching
is a boolean indicating whether the user's authentication status is currently being fetched.token
is a string representing the user's authentication token. This token is automatically appended to Chord API requests when the user has an active session.handleCallback
function completes the login process, when the user is redirected back to the site after clicking a link in their email. The SDK calls this function automatically when the Magic url parameter is detected on page load, so you are unlikely to need to call this function.getToken
function retrieves an authentication token for the current user session. While you are unlikely to need the token directly, since the SDK automatically appends it to relevant Chord API requests, you can use this function to check whether the user's session is still active. If the user's session has expired, getToken
will throw an error.getToken
on page load or when a user visits a protected route (like an account page) to check that their session has not expired since the last time you checked.login
function should be called when a user submits a login form. It will trigger an email to the user for verification.showUI
option controls whether Magic's default UI will display from when login
is called until the user clicks the link they've received in an email.logout
function terminates the user's current session.useCart()
cart
addPromoCode()
addReferralIdentifier()
addToCart()
checkout()
finalizeCheckout()
forgetCart()
forgetCart()
finalizeCheckout
and logout
, so no need to call it in those cases.loadCart()
modifyCart()
modifyQuantity()
modifyLineItem()
modifyGiftCards()
id
along with any of the following params: recipientName, recipientEmail, giftMessage, purchaserName, sendEmailAt.
The recipient email is a required field as that will be the account used to redeem the gift cards.removeFromCart()
removePromoCode
subscribeProduct()
endDate
is optional. The subscription will renew indefinitely if endDate
is not specified.useProduct()
useSubscription()
useSubscription
hook returns the current loaded subscription and functions for managing the subscription.subscription
subscription
object represents a subscription. You will need to explicitly call loadSubscription
before this object will be populated.loadSubscription()
loadSubscription
function loads information about the subscription from the Chord API.skipSubscription()
skipSubscription
function calls the Chord API to skip the next subscription delivery.cancelSubscription()
cancelSubscription
function calls the Chord API to cancel a subscription.pauseSubscription()
pauseSubscription
function calls the Chord API to pause a subscription.resumed
or theactionable_date
is reached.
Subscriptions can be either paused until a specifiedactionable_date
by sending an optionalactionable_date
param or paused indefinitely by not passing any params. The minimum date to whichactionable_date
can be set is the next day.resumeSubscription()
resumeSubscription
function calls the Chord API to resume a subscription.resumed
or theactionable_date
is reached.
Subscriptions can be resumed at a specifiedactionable_date
by sending an optionalactionable_date
param or resumed the next day (the minimum to which actionable_date
can be set) by not passing any params.updateSubscription()
updateSubscription
function calls the Chord API to update a subscription.shipAddressAttributes
and billAddressAttributes.
interval_unit
('day'/'week'/'month'/'year'), interval_length
, actionable_date
and the end_date
(null
for no end date ) can be updated.useTranslate
translate
function returned by the useTranslate
hook. translate
will load the specified string from your language resource file.translate
even if your site currently only supports one language. It's easier to edit your website text if it's all in a single configuration file, and it makes it trivial to add multi-language support in the future./src/intl/<language>.json
that looks like this:useUser()
useUser
hook returns the current user and functions for loading data about the user. At the moment, the only user information Chord supports is the user's referral identifier and personalized referral url.user
user
object represents the current user. You will need to explicitly call loadUser
or loadUserReferralIdentifier
before this object will be populated.loadUser()
loadUser
function loads information about the current order's associated user from the Chord API.loadUserReferralIdentifier()
loadUserReferralIdentifier
function loads the referral identifier information for a user with the given email address from the Chord API.modifyUser()
modifyUser
function is used to update the user's profile information.useSquareCheckout
modifyCart({ email: "[email protected]" })
. This is only needed for guest checkouts, if the user is logged in, this is not needed and the user's email will be used.updateOrderPayment()
function after retrieving the Square token client-side, using the Square Web Payment SDK.updateOrderAddresses()
updateOrderAddresses()
function is used to update the order's ship address. A valid ship address has the following format:getStates()
getStates()
function is used to retrieve information about countries and states available in the system to be used when we need to update the order's address. It takes the ISO code of the country and returns the list of states along with other information related to the country itself. updateOrderDelivery()
updateOrderDelivery()
function allows choosing the shipping option for the current order. At the moment we do not support multiple delivery options, so this function is only needed to move the checkout from the delivery step to the payment step. During this process, shipping costs and taxes will be added to the order. updateOrderPayment()
updateOrderPayment()
function allows completing the payment step of the checkout. Before using this function, the client should retrieve a token using the Web Payments SDK provided by Square. When the order is successfully completed, the payment source will be added to the user's wallet (for authenticated users only), allowing to re-use the payment token later, without having to input the credit card information again. finalizeCheckout()
finalizeCheckout()
is the last method that needs to be called to complete the order with Square. Call this method when you want to move the user to the thank you page and let them start a new order.