Giter Club home page Giter Club logo

forsbergplustwo / partner-metrics Goto Github PK

View Code? Open in Web Editor NEW
51.0 3.0 11.0 5.57 MB

Partner Metrics provides useful revenue metrics of your app, theme and affiliate revenue generated from the Shopify Partner Program.

Home Page: https://partnermetrics.io

License: GNU General Public License v3.0

Ruby 59.26% JavaScript 16.36% HTML 23.51% Procfile 0.04% Shell 0.08% CSS 0.76%
metrics-visualization rails ruby ruby-on-rails shopify-api shopify-apps

partner-metrics's Introduction

Partner Metrics

Partner Metrics is an open-source project providing you with metrics of your app, theme and affiliate revenue from the Shopify Partner program. Currently it calculates metrics based on monthly and yearly subscriptions, one-time charges and usage charges from Shopify.

This project is not officially related to Shopify in any way.

Usage

Partner Metrics was created by @forsbergplustwo, and will remain free to use at:

Development

Upgrading

The app in this repo was recently upgraded to Rails 7. If you had the earlier version running locally, you can upgrade by performing the following actions on your existing local app:

bin/rails db:migrate
bin/rails db:encryption:init
bin/rails create_initial_imports
bin/rails migrate_partner_api_credentials

Note: We recommend deleting your existing metrics data and re-importing to take advantage of improvements to churn calculations + yearly subscriptions support.

First time setup

  1. Setup dependencies, environment & database: bin/setup
  2. Start web server and sidekiq workers with: bin/dev

Visit localhost:4000

To run tests:

bin/rails test

# including system tests
bin/rails test:all

To import data from Partner API manually (once you have added your credentials in the app UI):

bin/rails import_all_from_partner_api

Deploying to Production

  1. Delete config/credentials/production.yml.enc
  2. Run bin/rails credentials:edit -e production and update as necessary
  3. If deploying to Heroku, make sure to set heroku config:set RAILS_MASTER_KEY=[key] where [key] is the value of your config/credentials/production.key file.
  4. Setup a cron job to run bin/rails import_all_from_partner_api on a daily basis.

Contributing

We'd love for you to contribute join us in making it better! In general, please follow the "fork-and-pull" Git workflow.

  1. Check out the Issues page, feel free to pick an existing issue or add a new one with clear title and description.
  2. Fork and clone the repo on GitHub
  3. Create a new branch for your fix or code improvement
  4. Run standardrb --fix to safely-autofix any linter or formatter corrections
  5. Commit changes to your own branch
  6. Push your work back up to your fork
  7. Submit a Pull request so that @forsbergplustwo can review your changes. Please link your PR to the existing issue if you are solving one.

Testing

We have a handful of MiniTests and Fixtures in the codebase, and welcome more. Please write MiniTests for new code you create.

Code of Conduct

Everyone interacting in Partner Metrics repository is expected to follow the Code of Conduct.

License

Partner Metrics is released under the GPLv3 License.

partner-metrics's People

Contributors

d-beck avatar daniel-sim avatar dependabot[bot] avatar emersonemerson avatar forsbergplustwo avatar janklimo avatar kirillplatonov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

partner-metrics's Issues

Refactor models/payment_histories.rb

Refactor models/payment_histories.rb to be more readable and maintainable (it's WILD at the moment 😅)

  • Move the logic for calculating the metrics into a metric::calculator class
  • Split the CSV import into separate class
  • Split the Partner API import into separate class
  • Update the Worker/Job to use the new classes etc.
  • Add tests

Use ActiveStorage for upload of CSV

We allow the user to upload a single CSV file for importing historical payment data. Currently it uses a js library and S3 for this, but that makes development & test harder. We'd like to replace this with ActiveStorage. Production should still use S3 (via ActiveStorage) but a simpler (local?) solution for dev and test would be really nice.

The files are quite large so we should use direct_upload feature from ActiveStorage if possible.

The user can upload either the zipped or unzipped file for storage.

We should setup a rake task to purge/destroy attached files (which will run daily in production) as the files is only needed during actual import and calculation, which happens just after upload.

uploading a new file replaces the existing file. So it would be has_one_attached

App Event based metrics

Big one, but would be great to support metrics based off the AppEvents endpoint from the Partner API.

Ideas

Use an Events model, for all types, including payments. So convert Payments and AppEvents into a single format.

Event types

  • Installed
  • Uninstalled
  • Converted
  • Paid
  • Acquired
  • Retained
  • Expanded
  • Reactivated
  • Contracted
  • Churned
  • Refunded

Note: A single app event or payment from shopify can result in multiple of the events above. For example “Uninstalled” may also create a “Churned” event if it was a previously paying shop.

Some events must be generated via a calculation, meaning all data must be present before those can be done correctly. Perhaps a processing pipeline lile this:

  • Import from CSV (historical revenue numbers only)
  • Import payments from API
  • Import events from API
  • Generate calculated events for these newly imported records
  • Calculate rollup metrics for each day

Events model

  • Date
  • Revenue type (monthly, yearly, onetime, usage, none)
  • Event type (from list above)
  • Shop (association)
  • App (association)
  • Gross amount
  • Shopify fee ampunt
  • Net amount
  • Calculated (true/false) -> Maybe needed for 2 step import + creating of additional event types..like Churned etc.

Rollup to Metric model

Events give us enough information to then
calculate daily aggregated records (with dimensions of revenue type, app & event type) for each final metric we want to display.

Monthly MRR
Monthly Churned MRR.
Monthly LTV
Monthly MRR expansion revenue
Yearly ARR…

We still don’t have a great way to track trials, BUT we can show Installs to paid conversions and “new” revenue metrics, which should be good enough.

Upgrade to Rails 7

One issue we will run into is that bootstrap gem is not available for newer rails versions. Perhaps we can precompile the bootstrap css asset (it uses variables and so needs to be compiled), then copy the generated file into a static CSS file in /app/assets/stylesheets. That allows us to remove the bootstrap gem, but keep a working stylesheet until we are ready.

Upgrade of Rails files diff: https://railsdiff.org/4.2.11.3/7.0.7.1

Pagination Missing on "Shop Summary" Merchant Table

LOVE PARTNERMETRICS JUST ONE ISSUE

Issue Description

On the "Shop Summary" page of our application, the table that displays the list of active merchants is currently limited to showing only 100 rows. This is problematic as we have over 400 merchants, and there seems to be no option or feature to navigate to the next set of rows (pagination) to view the rest of the merchants.

Steps to Reproduce

  1. Log in to the application.
  2. Navigate to the "Shop Summary" section.
  3. Observe the displayed table of active merchants.

Expected Behavior

The table should offer pagination controls (like next, previous page buttons) or some other mechanism to view all merchants, especially when their number exceeds the currently displayed limit of 100.

Actual Behavior

Only 100 merchants are displayed with no apparent way to access the remaining merchants.

Additional Information

  • Total number of merchants: 400+
  • Currently displayed: 100

I'm a human. Please be nice.

Checklist
  • Create app/controllers/shops_controller.rb95f238d Edit
  • Running GitHub Actions for app/controllers/shops_controller.rbEdit
  • Create app/views/shops/index.html.erbc5f6448 Edit
  • Running GitHub Actions for app/views/shops/index.html.erbEdit
  • Create app/helpers/pagination_helper.rb8d4915f Edit
  • Running GitHub Actions for app/helpers/pagination_helper.rbEdit
  • Modify config/routes.rbb80e3a3 Edit
  • Running GitHub Actions for config/routes.rbEdit

Add support for package.json assets

Having this available will make adding things like turbo, stimulus and other good stuff so much easier. Once we have stimulus we can remove jQuery dependencies etc as well 😎

Is esbuild the go to for rails projects these days?

Error first on setup

I cloned the app and tried to run it for the first time but I keep getting the error below after running bin/setup

rails aborted!
NoMethodError: undefined method []' for nil:NilClass /Users/keem/projects/partner-metrics/config/application.rb:36:in class:Application'
/Users/keem/projects/partner-metrics/config/application.rb:22:in <module:PartnerMetrics>' /Users/keem/projects/partner-metrics/config/application.rb:21:in

'
/Users/keem/projects/partner-metrics/Rakefile:4:in require_relative' /Users/keem/projects/partner-metrics/Rakefile:4:in '
bin/rails:4:in `'
(See full trace by running task with --trace)

== Command ["bin/rails db:prepare"] failed ==

The error seems to point to the line below

config.active_record.encryption.primary_key = Rails.application.credentials[:active_record_encryption][:primary_key]

Any idea how I fix this ? Do I need to change the value in the credentials file ?

Multi-tenancy accounts

Current only a single user can view their data. It's often requested by users that we introduce an Account model, so multiple users can login to the same account. On signup first user fills out the Partner Organization Name, which creates the account.

Some initial thoughts:

  • All metrics & payments would need to be associated with the Account level instead of user
  • Migrate all existing data to the Account model structure
  • First user is an Admin, and can choose if others are admin
  • Only admin can update account level features (api credentials, upload data, invite other users etc.)
  • As we will have limited features related to admin permissions, I don't think we should add dependencies on CanCanCan or other Role based gems.

A number of challenges

  • I added my partner API credentials, Is there a button I should push to sync?
  • No where does it show which app I am looking at the numbers for
  • How do I switch between partner apps in the dashboard

I'm a human. Please be nice.

Cleanup models

  • Move things to correct model
  • DRY up repeated code
  • Refactor long methods
  • Use scopes where possible
  • Add basic tests

Cleanup controllers

  • Move things to correct RESTful controllers/actions
  • DRY up repeated code
  • Refactor long methods
  • Add basic tests

Connection problem of Sideqik with Redis

Hello Team,

I'm trying to set up this app on a linux machine.

Server details:

PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

Problem statement:

When I execute the bin/dev command as mentioned in the readme.md file, then I can see this error

Screenshot 2023-11-21 at 7 41 29 PM

Sideqik is trying to connect with Redis but it's not connected successfully.

PaymentHistories via Partner API does not include shop_country

When importing from the Shopify Partner API via GraphQL, the import_partner_api method does not include the shop_country when creating the PaymentHistory records, which results in the app showing NULL:

image

The initial CSV import does include shop_country so we see it after initial import, but then NULL starts creeping in more and more over time as the payments are imported from the API daily.

Note: There is no way to fix this, as the Shopify Partner API does not provide the shop country information: https://shopify.dev/docs/api/partner/2023-10/objects/Shop

Importing a Payout is returning a 403

Thanks a lot for the platform. I've been looking for a tool like this since quite some time.

I am trying to import my payouts data inside the platform. Everytime I do it, looks like the page is breaking and I can see the errors in the Console/Network tabs. Here's what the platform looks like after a broken import:

CleanShot 2023-09-21 at 14 08 21

Steps to reproduce

  1. In Shopify, click on Export CSV and export All Payouts
  2. Upload the received CSV in https://www.partnermetrics.io/imports/new
  3. See the broken pages and no new data.

I also tried to ZIP the CSV because the box was telling to use a ZIP. Thanks!

Note marker feature

It would be great to support a Note marker style feature, where you can add notes to graphs on certain dates. For example, you may want to add a note marker on the date that you made a pricing change or update your Shopify App Store listing.

  • Add a note marker resource (date, note text, optional association to to specific app_title). index, new, create, update, destroy.
  • User option to include note markers on main graph
  • Update main chart to show the note markers as vertical line marker, with hover showing text

Cleanup GraphQL related code

GraphQL is only used in one place, models/payment_histories.rb

It would be great to clean up the implementation, to make it less "noisy" in the file. Ideas:

Usage charges could be one-time or recurring, depending on user preference

Currently, the app will treat usage charges as one-time payments. This is technically correct, but in some cases the user may want those usage charges counted as recurring revenue. I do this myself, as one of my apps uses usage charges for the actual subscription charge, depending on amount of use. Now I also have another user that wants the same, and so it may make sense to have this as an option.

1- On the Account connection modal, under the api credentials, we have a radio form control:

a) Count "usage charges" as one-time revenue
b) Count "usage charges" as recurring revenue

a) is the default for new accounts

This then saves to the current_user along with the other credentials, and checked when importing payments. Currently I have some rough logic that does this, based on my email address. This could be replaced with a check against the above field instead.

Import status modification

Hi @forsbergplustwo
After execution of import_all_from_partner_api , i can see import status is set as scheduled in APP

Screenshot 2023-11-24 at 1 44 45 PM

Can you please let me know badge status will set completed automatically and data will import in APP or i need to execute other command?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.