├── LICENSE ├── README.md ├── analysis └── .gitkeep ├── data └── .gitkeep ├── dbt_project.yml ├── logs ├── dbt.log ├── dbt.log.2018-04-06 ├── dbt.log.2018-04-13 ├── dbt.log.2018-04-18 ├── dbt.log.2018-05-16 ├── dbt.log.2018-05-18 ├── dbt.log.2018-07-28 └── dbt.log.2018-07-29 ├── macros ├── .gitkeep ├── get_column_values.sql ├── get_url_parameter.sql ├── split_part.sql └── table_exists.sql ├── models ├── admin │ ├── mappings_ga_proc.sql │ ├── monthend_dates.sql │ └── stores_proc.sql ├── base │ ├── ga │ │ └── ga_transactions.sql │ └── shopify │ │ ├── shopify_customers_proc.sql │ │ ├── shopify_discounts_proc.sql │ │ ├── shopify_orders_proc.sql │ │ ├── shopify_products_proc.sql │ │ └── shopify_refunds_proc.sql ├── join │ ├── agg_customers.sql │ ├── agg_transactions.sql │ ├── customers_by_transaction.sql │ └── transaction_by_order_number.sql └── math │ └── buyer-segmentation │ ├── buyer_segment_lists.sql │ ├── buyer_segment_stats.sql │ ├── customers_proc.sql │ ├── customers_proc_qoq.sql │ ├── customers_proc_yoy.sql │ ├── segment_proc_buyers.sql │ ├── segment_stats_buyers_agg.sql │ └── segment_stats_buyers_view.sql ├── target └── graph.gpickle └── tests └── .gitkeep /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Coding is for Losers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Shopify + Google Analytics Buyer Segmentation 2 | SQL models (written in the [DBT](https://getdbt.com) framework) for performing Shopify + Google Analytics buyer segmentation analysis. 3 | 4 | To get set up... 5 | 6 | 1) Read the blog post at: 7 | https://codingisforlosers.com/shopify-google-analytics-buyer-segmentation 8 | 9 | 2) Make a copy of the Tracking Plan in Sheets, which contains step-by-step instructions on setting up this analysis: https://docs.google.com/spreadsheets/d/1Y9x7u4dOj1wsicwax-1XkritRaMzvKMOsU8lgIOEkLY/copy 10 | 11 | Questions? Holler to help@codingisforlosers.com. 12 | -------------------------------------------------------------------------------- /analysis/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coding-is-for-losers/shopify-buyer-segmentation/ebda4642ceda713d0f5954503189c29c64f703ff/analysis/.gitkeep -------------------------------------------------------------------------------- /data/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coding-is-for-losers/shopify-buyer-segmentation/ebda4642ceda713d0f5954503189c29c64f703ff/data/.gitkeep -------------------------------------------------------------------------------- /dbt_project.yml: -------------------------------------------------------------------------------- 1 | 2 | # Name your package! Package names should contain only lowercase characters 3 | # and underscores. A good package name should reflect your organization's 4 | # name or the intended use of these models 5 | name: 'shopify_buyer_segmentation' 6 | version: '1.0' 7 | 8 | # This setting configures which "profile" dbt uses for this project. Profiles contain 9 | # database connection information, and should be configured in the ~/.dbt/profiles.yml file 10 | profile: 'your-dbt-profile-here' 11 | 12 | # These configurations specify where dbt should look for different types of files. 13 | # The `source-paths` config, for example, states that source models can be found 14 | # in the "models/" directory. You probably won't need to change these! 15 | source-paths: ["models"] 16 | analysis-paths: ["analysis"] 17 | test-paths: ["tests"] 18 | data-paths: ["data"] 19 | macro-paths: ["macros"] 20 | 21 | target-path: "target" # directory which will store compiled SQL files 22 | clean-targets: # directories to be removed by `dbt clean` 23 | - "target" 24 | - "dbt_modules" 25 | 26 | # You can define configurations for models in the `source-paths` directory here. 27 | # Using these configurations, you can enable or disable models, change how they 28 | # are materialized, and more! 29 | 30 | # In this example config, we tell dbt to build all models in the example/ directory 31 | # as views (the default). Try changing `view` to `table` below, then re-running dbt 32 | 33 | 34 | models: 35 | shopify_buyer_segmentation: 36 | admin: 37 | materialized: table 38 | base: 39 | materialized: table 40 | join: 41 | materialized: table 42 | math: 43 | materialized: table -------------------------------------------------------------------------------- /logs/dbt.log.2018-05-16: -------------------------------------------------------------------------------- 1 | 2018-05-16 10:14:13,895: Tracking: tracking 2 | 2018-05-16 10:14:13,905: Sending event: {'category': 'dbt', 'action': 'invocation', 'label': 'start', 'context': [, , ]} 3 | 2018-05-16 10:14:14,818: Loading dependency project from /usr/local/Cellar/dbt/0.9.0/libexec/lib/python3.6/site-packages/dbt/include 4 | 2018-05-16 10:14:14,863: Loading dependency project from /Users/davidkrevitt/Dropbox/CIFL/adp-models/growth-engines/dbt_modules 5 | 2018-05-16 10:14:14,864: Parsing get_column_values.sql 6 | 2018-05-16 10:14:14,905: Parsing get_url_parameter.sql 7 | 2018-05-16 10:14:14,913: Parsing split_part.sql 8 | 2018-05-16 10:14:14,922: Parsing table_exists.sql 9 | 2018-05-16 10:14:14,933: Parsing core.sql 10 | 2018-05-16 10:14:14,949: Parsing adapters/bigquery.sql 11 | 2018-05-16 10:14:14,957: Parsing adapters/common.sql 12 | 2018-05-16 10:14:14,977: Parsing adapters/postgres.sql 13 | 2018-05-16 10:14:14,984: Parsing adapters/redshift.sql 14 | 2018-05-16 10:14:15,012: Parsing etc/get_custom_schema.sql 15 | 2018-05-16 10:14:15,024: Parsing materializations/archive.sql 16 | 2018-05-16 10:14:15,067: Parsing materializations/bigquery.sql 17 | 2018-05-16 10:14:15,083: Parsing materializations/helpers.sql 18 | 2018-05-16 10:14:15,112: Parsing materializations/incremental.sql 19 | 2018-05-16 10:14:15,146: Parsing materializations/table.sql 20 | 2018-05-16 10:14:15,172: Parsing materializations/view.sql 21 | 2018-05-16 10:14:15,190: Parsing materializations/wrapper.sql 22 | 2018-05-16 10:14:15,196: Parsing schema_tests/accepted_values.sql 23 | 2018-05-16 10:14:15,202: Parsing schema_tests/not_null.sql 24 | 2018-05-16 10:14:15,208: Parsing schema_tests/relationships.sql 25 | 2018-05-16 10:14:15,214: Parsing schema_tests/unique.sql 26 | 2018-05-16 10:14:15,372: Parsing model.agency_data_pipeline.accounts_proc 27 | 2018-05-16 10:14:15,384: Sending event: {'category': 'dbt', 'action': 'invocation', 'label': 'end', 'context': [, , ]} 28 | 2018-05-16 10:14:15,742: Encountered an error: 29 | 2018-05-16 10:14:15,742: Compilation Error in model accounts_proc (models/admin/accounts_proc.sql) 30 | Required var 'bigquery-project' not found in config: 31 | Vars supplied to accounts_proc = {} 32 | 2018-05-16 10:14:15,802: Traceback (most recent call last): 33 | File "/usr/local/Cellar/dbt/0.9.0/libexec/lib/python3.6/site-packages/dbt/main.py", line 40, in main 34 | results, succeeded = handle_and_check(args) 35 | File "/usr/local/Cellar/dbt/0.9.0/libexec/lib/python3.6/site-packages/dbt/main.py", line 84, in handle_and_check 36 | task, res = run_from_args(parsed) 37 | File "/usr/local/Cellar/dbt/0.9.0/libexec/lib/python3.6/site-packages/dbt/main.py", line 138, in run_from_args 38 | results = run_from_task(task, proj, parsed) 39 | File "/usr/local/Cellar/dbt/0.9.0/libexec/lib/python3.6/site-packages/dbt/main.py", line 146, in run_from_task 40 | result = task.run() 41 | File "/usr/local/Cellar/dbt/0.9.0/libexec/lib/python3.6/site-packages/dbt/task/compile.py", line 25, in run 42 | results = runner.run(query, CompileRunner) 43 | File "/usr/local/Cellar/dbt/0.9.0/libexec/lib/python3.6/site-packages/dbt/runner.py", line 221, in run 44 | return self.run_from_graph(Selector, Runner, query) 45 | File "/usr/local/Cellar/dbt/0.9.0/libexec/lib/python3.6/site-packages/dbt/runner.py", line 183, in run_from_graph 46 | flat_graph, linker = self.compile(self.project) 47 | File "/usr/local/Cellar/dbt/0.9.0/libexec/lib/python3.6/site-packages/dbt/runner.py", line 179, in compile 48 | (flat_graph, linker) = compiler.compile() 49 | File "/usr/local/Cellar/dbt/0.9.0/libexec/lib/python3.6/site-packages/dbt/compilation.py", line 278, in compile 50 | root_project, all_projects) 51 | File "/usr/local/Cellar/dbt/0.9.0/libexec/lib/python3.6/site-packages/dbt/loader.py", line 23, in load_all 52 | loader.load_all(root_project, all_projects, macros)) 53 | File "/usr/local/Cellar/dbt/0.9.0/libexec/lib/python3.6/site-packages/dbt/loader.py", line 48, in load_all 54 | project, project_name, macros)) 55 | File "/usr/local/Cellar/dbt/0.9.0/libexec/lib/python3.6/site-packages/dbt/loader.py", line 85, in load_project 56 | macros=macros) 57 | File "/usr/local/Cellar/dbt/0.9.0/libexec/lib/python3.6/site-packages/dbt/parser.py", line 338, in load_and_parse_sql 58 | return parse_sql_nodes(result, root_project, all_projects, tags, macros) 59 | File "/usr/local/Cellar/dbt/0.9.0/libexec/lib/python3.6/site-packages/dbt/parser.py", line 282, in parse_sql_nodes 60 | macros=macros) 61 | File "/usr/local/Cellar/dbt/0.9.0/libexec/lib/python3.6/site-packages/dbt/parser.py", line 231, in parse_node 62 | capture_macros=True) 63 | File "/usr/local/Cellar/dbt/0.9.0/libexec/lib/python3.6/site-packages/dbt/clients/jinja.py", line 171, in get_rendered 64 | return render_template(template, ctx, node) 65 | File "/usr/local/Cellar/dbt/0.9.0/libexec/lib/python3.6/site-packages/dbt/clients/jinja.py", line 158, in render_template 66 | return template.render(ctx) 67 | File "/usr/local/Cellar/dbt/0.9.0/libexec/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render 68 | return original_render(self, *args, **kwargs) 69 | File "/usr/local/Cellar/dbt/0.9.0/libexec/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in render 70 | return self.environment.handle_exception(exc_info, True) 71 | File "/usr/local/Cellar/dbt/0.9.0/libexec/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception 72 | reraise(exc_type, exc_value, tb) 73 | File "/usr/local/Cellar/dbt/0.9.0/libexec/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise 74 | raise value.with_traceback(tb) 75 | File "