One disadvantage of building Shopify apps is that by default only Shopify maintains the list of your app's customers. That means you don't really have a good way of knowing who they are or communicating with them. Unless, of course, you maintain your own customer database along with Shopify.
Your own Shopify customer database
Once you have your own customer database, business will become much easier
- Want to talk to a few customers about a new feature you're considering? Email them one by one.
- Written a great blog post about how to use your app? Send your customers an email as part of your mailing list.
- Wanting to run some saas analytics on your customer base to find out your churn and LTV? You got the data.
Getting the Shop data
Building your own customer database is actually easier than you think.
When a store owner installs your app, near the end of the OAuth authentication process Shopify sends you a request which includes the shop's myshopify.com name and the access_token
.
Once you have that, you can make an API call to get the rest of the data for the Shop. Inside that Shop data is the contact information you need to build up your own customer database.
An example of this data is below. This is the full data from when this article was written but I encourage you to review the full API to see if there's anything changed.
{ "id" => 8431627, "name" => "Little Stream Software Dev", "email" => "eric@example.com", "domain" => "little-stream-software-dev.myshopify.com", "created_at" => "2015-04-23T16:54:53-04:00", "province" => "Oregon", "country" => "US", "address1" => "123 Main St", "zip" => "97007", "city" => "Aloha", "source" => "littlestream", "phone" => "8675309", "updated_at" => "2015-10-07T19:38:08-04:00", "customer_email" => "inbox@example.com", "latitude" => 45.4, "longitude" => -122.8, "primary_location_id" => nil, "primary_locale" => "en", "country_code" => "US", "country_name" => "United States", "currency" => "USD", "timezone" => "(GMT-05:00) Eastern Time (US & Canada)", "iana_timezone" => "America/New_York", "shop_owner" => "Eric Davis", "money_format" => "$ ", "money_with_currency_format" => "$ USD", "province_code" => "OR", "taxes_included" => false, "tax_shipping" => nil, "county_taxes" => true, "plan_display_name" => "affiliate", "plan_name" => "affiliate", "has_discounts" => false, "has_gift_cards" => false, "myshopify_domain" => "little-stream-software-dev.myshopify.com", "google_apps_domain" => nil, "google_apps_login_enabled" => nil, "money_in_emails_format" => "$", "money_with_currency_in_emails_format" => "$ USD", "eligible_for_payments" => true, "requires_extra_payments_agreement" => false, "password_enabled" => false, "has_storefront" => true, "eligible_for_card_reader_giveaway" => true, "setup_required" => false, "force_ssl" => false }
Picking through this data you can easily build up a customer record and save it to your database. On smaller apps I recommend putting that information along with the Shop data, but on larger ones or ones that aren't pure Shopify-only apps I'll use a Customer or Shopify record and associate that to your app data.
class Shop < ActiveRecord::Base def retrieve_and_save_store_data session = ShopifyAPI::Session.new(self.shopify_domain, self.shopify_token)
@shop\_data = ShopifyAPI::Shop.current
self.shop\_email = @shop\_data.email
self.shop\_customer\_email = @shop\_data.customer\_email
self.shop\_name = @shop\_data.name
self.save
end end
Make sure you use the correct email address fields. customer_email
is the one used by the Shop for contacting customers while email
is the account owner's email address.
Already installed stores
For stores that have already installed your app, it's easy to go back and pull down their data. You'll want to do this outside of a regular web request/response cycle using a background job, rake task, or even just a command-line script.
I even recommend running something like this every week or so to make sure you keep your customer data up-to-date.
# Rake task desc "Update shop data from Shopify" task :update_shops => :environment do Shop.find_each.each do |shop| shop.with_shopify_session do shop.retrieve_and_save_store_data end end end
The good thing about having a copy of your customers is that it opens up more things you can do with that data. As long as you keep the data fresh and act responsibly, you should be able to do a lot with it.