Skip to content

Instantly share code, notes, and snippets.

@vutran0111
Last active October 23, 2017 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vutran0111/9611d3cf0cc1369a3ffb524d3c7dea38 to your computer and use it in GitHub Desktop.
Save vutran0111/9611d3cf0cc1369a3ffb524d3c7dea38 to your computer and use it in GitHub Desktop.

Usage

  • Create new webhooks with event checkout update on shopify.
  • Add URl handle webhooks : your-domain/shopify_webhooks/checkout.


Process checkout webhooks

Here is list of supported webhook events of shopify. And for now, we just doing with checkout webhook.

Everytime we receice webhooks request, it will be verified by method verify_request into ShopifyWebhooksController before continue process data. More detail about verify webhook request is here.

Note: We use signing_key instead of share_secret_key, we can find it by go to Settings > Notifications and look into section Webhooks.

Segment checkout values for ecommerce stuff which referenced

https://segment.com/docs/spec/ecommerce/v2/#checkout-started

1. Checkout data send to segment

This properties we care about for now:

Property Type Description
order_id string Checkout ID
value number The sum of all the prices of all the items in the checkout, taxes and discounts included.
revenue number Price of the checkout before shipping and taxes
shipping number Shipping cost
tax number The sum of all the taxes applied to the line items in the checkout.
discount number Total discounts
currency string Currency code
products number Total products in the checkout

For detail properties supports by segnment [checkout creation] (https://segment.com/docs/spec/ecommerce/v2/#checkout-started)

Checkout response from checkout webhook. On List of supported webhook events and topics, click View Response of row Checkout to see that.

2. Customer data send to segment

When customer data included in checkout webhook request, we'll create new an identity based on the id of checkout webhook and any other traits available and invite them prior to sending the segment event as an identify segment call. If there's no customer data then do nothing.

We use a hardcoded array (WHITELIST_TRAITS) that can be used as a whitelist for shopify traits we care about.

For now, array that we use as below:

WHITELIST_TRAITS = ["email", "first_name", "last_name", "phone", "orders_count", "total_spent", "state", "verified_email"]

Trait Type
email string
first_name string
last_name string
phone string
orders_count number
total_spent string
state string
verified_email string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment