-
Notifications
You must be signed in to change notification settings - Fork 50
DEVDOCS-6321: [new] Data events API #876
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5669e3b
Create data-events.mdx: [new] Data events API
bc-traciporter 15b5b8f
Update data-events.mdx
bc-traciporter 6684bca
Update data-events.mdx
bc-traciporter 899b1ae
Update data-events.mdx
bc-traciporter 03149a5
Update data-events.mdx
bc-traciporter c813326
Update data-events.mdx
bc-traciporter 0621c16
Update data-events.mdx
bc-traciporter 9360eee
Updates per Roman
bc-traciporter a3abf80
Updates per Roman
bc-traciporter 07521d3
additional intro info by Roman
bc-traciporter 3458965
Merge branch 'main' into DEVDOCS-6321
bc-traciporter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
# Data Events in the GraphQL Storefront API | ||
|
||
This article explains how to enable headless storefronts to utilize native analytics. The BigCommerce analytics system operates on data events. These are event objects that capture specific user actions such as adding a product to a cart, visiting a website, or placing an order. All of the BigCommerce analytics features rely on event data being transmitted to our data pipeline. | ||
|
||
This API is particularly useful for tracking analytical metrics, including visits and product views. | ||
|
||
## Introduction | ||
|
||
A fundamental concept in BigCommerce analytics is the visit details. When sending events to BigCommerce, you must include a `visitId` and `visitorId`, each formatted as a UUID. The `visitId` represents a session within the data pipeline, while the `visitorId` identifies a visitor or shopper. The `visitId` is typically stored in a short-lived cookie. In Stencil, its default time-to-live (TTL) is 30 minutes and we recommend using the same TTL for headless stores. In contrast, the `vistorId` is assigned to a shopper and has a TTL of one year in Stencil. You can generate these values using the [UUID Generator](https://www.uuidgenerator.net/version4). Below, we outline the steps for enabling a headless storefront, along with an example implementation. | ||
bc-traciporter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Enabling a headless storefront | ||
|
||
<Steps> | ||
### Initiate a visit using the `VisitStartedEvent` mutation. | ||
|
||
Execute the `VisitStartedEvent` mutation at the start of a shopper's session. You must provide the `visitId` and `visitorId` (in UUID format) in the `initiator` input. This action registers a new visit in the data pipeline. Use the same `visitId` for all further events within the session to ensure they are linked to the same visit. | ||
|
||
<Tabs items={['Request', 'Response']}> | ||
<Tab> | ||
|
||
```http filename="Example query: VisitStartedEvent" showLineNumbers copy | ||
POST https://api.bigcommerce.com/stores/{{STORE_HASH}}/graphql | ||
X-Auth-Token: {{ACCESS_TOKEN}} | ||
Content-Type: application/json | ||
Accept: application/json | ||
|
||
mutation VisitStartedEvent { | ||
analytics { | ||
visitStartedEvent(input: { | ||
commonInput: { | ||
initiator: { | ||
visitId: "5acfce80-0d45-47b9-adca-d2d894e60444", | ||
visitorId: "a1711d5c-59a1-4b67-8880-cff92d591444" | ||
}, | ||
request: { | ||
url: "www.bigcommerce.com", | ||
userAgent: "PostmanRuntime" | ||
}, | ||
consent: { | ||
targeting: true, | ||
analytics: true, | ||
functional: true | ||
} | ||
} | ||
}) { | ||
executed | ||
} | ||
} | ||
} | ||
``` | ||
</Tab> | ||
<Tab> | ||
|
||
```json filename="Example query: Get data layer enabled flag" showLineNumbers copy | ||
{ | ||
"data": { | ||
"analytics": { | ||
"visitStartedEvent": { | ||
"executed": true | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
</Tab> | ||
</Tabs> | ||
|
||
|
||
### Track product views with the `ProductViewedEvent` mutation | ||
|
||
Execute the `ProductViewedEvent` mutation whenever a shopper views product details. Use the same `visitId` and `visitorId` as in the `VisitStartedEvent`. This step registers a product view in the data pipeline and links the product view to the session. | ||
|
||
<Tabs items={['Request', 'Response']}> | ||
<Tab> | ||
|
||
```http filename="Example query: ProductViewedEvent" showLineNumbers copy | ||
POST https://api.bigcommerce.com/stores/{{STORE_HASH}}/graphql | ||
X-Auth-Token: {{ACCESS_TOKEN}} | ||
Content-Type: application/json | ||
Accept: application/json | ||
|
||
mutation ProductViewedEvent { | ||
analytics { | ||
productViewedEvent(input: { | ||
commonInput: { | ||
initiator: { | ||
visitId: "5acfce80-0d45-47b9-adca-d2d894e60444", | ||
visitorId: "a1711d5c-59a1-4b67-8880-cff92d591444" | ||
}, | ||
request: { | ||
url: "www.bigcommerce.com", | ||
userAgent: "PostmanRuntime" | ||
}, | ||
consent: { | ||
targeting: true, | ||
analytics: true, | ||
functional: true | ||
} | ||
}, | ||
productInput: { | ||
productEntityId: 88, | ||
searchKeyword: "test" | ||
} | ||
}) { | ||
executed | ||
} | ||
} | ||
} | ||
``` | ||
</Tab> | ||
<Tab> | ||
|
||
```json filename="Example query: ProductViewedEvent" showLineNumbers copy | ||
{ | ||
"data": { | ||
"analytics": { | ||
"productViewedEvent": { | ||
"executed": true | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
</Tab> | ||
</Tabs> | ||
|
||
### Redirect to checkout with the `Redirect` mutation | ||
|
||
After adding a product to a cart and obtaining a `cart_id`, execute the `redirect` mutation. Use the same `visitId` and `visitorId` as in the `VisitStartedEvent` and specify the `cart_id`. This step generates a `redirectedCheckoutUrl`. | ||
|
||
<Tabs items={['Request', 'Response']}> | ||
<Tab> | ||
|
||
```http filename="Example query: Redirect" showLineNumbers copy | ||
POST https://api.bigcommerce.com/stores/{{STORE_HASH}}/graphql | ||
X-Auth-Token: {{ACCESS_TOKEN}} | ||
Content-Type: application/json | ||
Accept: application/json | ||
|
||
mutation redirect { | ||
cart { | ||
createCartRedirectUrls (input: { | ||
cartEntityId: "2c0b561a-1288-4d21-b5b1-4009b75e38e2", | ||
visitId: "5acfce80-0d45-47b9-adca-d2d894e60444", | ||
visitorId: "a1711d5c-59a1-4b67-8880-cff92d591444" | ||
}) { | ||
redirectUrls { | ||
redirectedCheckoutUrl, | ||
embeddedCheckoutUrl | ||
} | ||
errors { | ||
... on Error { | ||
message | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
</Tab> | ||
<Tab> | ||
|
||
```json filename="Example query: Redirect" showLineNumbers copy | ||
{ | ||
"data": { | ||
"cart": { | ||
"createCartRedirectUrls": { | ||
"redirectUrls": { | ||
"redirectedCheckoutUrl": | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
</Tab> | ||
</Tabs> | ||
|
||
### Complete the order | ||
|
||
Navigate to the `redirectedCheckoutUrl` returned in the previous step, proceed through checkout, and create an order. At this point, the `Bigcommerce app` sends `Checkout` and `Order` related events to the data pipeline. Navigating to the above `redirectedCheckoutUrl` ensures the BigCommerce app links all further events to the same visit within the session. | ||
</Steps> | ||
|
||
By following these steps, you ensure that your headless storefront properly captures analytics events and sends relevant data to the BigCommerce analytics system. | ||
|
||
## Verification | ||
|
||
In the control panel, go to **Analytics** > **Marketing** and select the `Direct` origin from the table to view the origins. | ||
|
||
Also, navigate to **Analytics** > **Purchase funnel** and observe the `Shopped` metric, which represents product views. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.