My goal is to check if I am on the Thank You page. If yes, I want to add a div somewhere in here that contains some information about the order. I have a few questions:
-
Should my checking if I am on Thank you page suffice? I am almost sure that it is not so I’m hoping to get the Shopify object to ensure my Thank You page check.
-
Where can I see the list of analytics events that I can subscribe to?
See code below:
import { register } from '@shopify/web-pixels-extension'
register(({ configuration, analytics, browser, init }) => {
const { window } = init.context
console.log(window.Shopify) // This returns undefined
// Subscribe to Page Viewed event
analytics.subscribe('page_viewed', async (event) => {
// Check if customer is on Thank You page
if (
event.context.document.title.startsWith('Thank you')
) {
console.log('I am on Thank You page')
const sectionContent = document.querySelector('.section__content')
const secondContentBox = sectionContent.querySelector(
'.content-box:nth-child(2)'
)
const newDiv = document.createElement('div')
newDiv.innerHTML = `I WANT TO INSERT SOMETHING`
sectionContent.insertBefore(newDiv, secondContentBox)
}
})
})