Metadocumentation
open-collective
open-collective
  • Welcome
  • About
    • Introduction
    • Terminology
    • Company
    • Pricing
    • Community Guidelines
    • Values
    • Team
    • Investors
    • Contributing
  • Product
    • Features
    • Roadmap
    • Comparison
    • User Profile
    • Currencies
    • Log-in System
  • Collectives
    • FAQ
    • Creating a Collective
    • Quick Start Guide
    • Customize Collective
    • Change Core Contributors
    • Tiers & Goals
    • Add Fiscal Host
    • Change Fiscal Host
    • Transparent Budget
    • Expense Policy
    • Approving Expenses
    • Updates & Comms
    • Events
    • Funding Options
    • Data Export
    • Buttons & Banners
    • Integrations
    • Zero Collective Balance
    • Closing a Collective
  • Financial Contributors
    • FAQ
    • Payments
    • Website Badge
    • Organizations
      • FAQ
      • Bulk Transfers
      • Gift Cards
      • Sustainer Resources
    • Collectives
      • Collective to Collective donations
  • Expenses & Getting Paid
    • FAQ
    • Submitting Expenses
    • Expense Comments
    • Edit an Expense
    • Tax Information
  • Fiscal Hosts
    • FAQ
    • Becoming a Fiscal Host
    • Create a Fiscal Host
    • Fiscal Host Settings
    • Invoices
    • Payouts
    • Host Dashboard
    • Add Funds Manually
    • Refunds
    • Host Fees
    • Local Tax Support
    • Agreement Templates
    • Open Source Collective
  • Contributing
    • Design
      • Design Workflow
      • Design Contribution Guidelines
    • Development
      • Contribution Guide
      • Best Practice Guidelines
      • Bounties
      • API
        • Members
        • Users / Emails
        • Collectives
        • Events
      • README Integration
      • Architecture
      • Postgres Database
      • PayPal
      • Post-Donation Redirect
      • Custom Tweets
      • Manual Reporting
      • Github Permissions
      • Translations
      • Testing with Cypress
      • Collective's locations
    • Documentation
      • Style guide
      • Suggesting changes
    • Translation
  • Internal
    • Scope
    • Team Retreats
    • Brussels Summer Team Retreat
    • Host Admin Manual
    • Newsletter
    • Support
    • Issue Labels
    • DNS Troubleshooting
    • Developer Guidelines
    • Architecture
    • Testing
    • Queries
      • Gift Cards
      • Transactions
      • Ops
      • Collectives
      • Hosts
      • Analytics
      • Emails
    • Projects
      • Maintainerati Berlin 2019
      • Season of Docs 2019
    • The Open Collective Way
      • Values
      • Community Guidelines
      • Core Contributors Guidelines
      • Core Contributors: Communication
      • Core Contributors: Expenses
      • Core contributors: Leave
      • Core Contributors: Compensation
Powered by GitBook
On this page
  • Gift cards created and claims per month
  • Total amount donated using gift cards by issuer and currency
  • Total number of Github contributors reached
  1. Internal
  2. Queries

Gift Cards

Gift cards created and claims per month

SELECT 
date_trunc('month', pm."createdAt") as "month",
count(*),
sum(
CASE
WHEN pm."CollectiveId" = spm."CollectiveId" THEN 0
WHEN pm."CollectiveId" != spm."CollectiveId" THEN 1
END) as "totalClaimed"
FROM "PaymentMethods" pm
LEFT JOIN "PaymentMethods" spm ON spm.id=pm."SourcePaymentMethodId"
WHERE pm.service='opencollective'
  AND pm.type='virtualcard'
GROUP by month

Total amount donated using gift cards by issuer and currency

SELECT max(spmc.slug) as "gift card issuer", sum(amount) / 100 as "totalAmount", t.currency
FROM "Transactions" t
LEFT JOIN "PaymentMethods" pm ON t."PaymentMethodId" = pm.id
LEFT JOIN "PaymentMethods" spm ON pm."SourcePaymentMethodId" = spm.id
LEFT JOIN "Collectives" spmc ON spmc.id = spm."CollectiveId"
WHERE t.type = 'CREDIT'
  AND t."OrderId" IS NOT NULL
  AND pm.service = 'opencollective'
  AND pm.type = 'virtualcard'
GROUP BY spm."CollectiveId", t.currency

Total number of Github contributors reached

This query will show a company how many unique contributors are participating to projects they have donated to through gift cards. Useful for companies that are donating to open-source as a way to promote their services to developers.

SELECT count(*) FROM (
    SELECT * FROM (
        SELECT json_object_keys((c.DATA ->> 'githubContributors')::json) AS contributors
        FROM "Transactions" t
        INNER JOIN "Collectives" c ON c.id = t."CollectiveId"
        WHERE t."UsingVirtualCardFromCollectiveId" = -- PUT THE COLLECTIVE ID HERE --
        AND t."type" = 'CREDIT'
        AND c.DATA IS NOT NULL
        AND c.DATA ->> 'githubContributors' IS NOT null
        GROUP BY c.id
    ) AS all_contributors
    GROUP BY contributors
) AS total_contributors
PreviousQueriesNextTransactions

Last updated 5 years ago