May 8, 2019

Pulling data from Gumroad sales graph

Alex Hillman @alexhillman

Has anybody tried pulling the stats out of the gumroad sales graph?

Specifically, I'm trying to "export" the views and sales count for each day from this graph, which don't seem to be exportable as a CSV or via the API in any way.

Any clever ways to pull the data that's being charted here?

  1. 2

    Ah yeah, I hit this with my old ebooks. The best solution I've found is to:

    1. Log in so they can get your user id from cookies
    2. Manually build a URL like this
    3. Grab the data you want out of the JSON response

    No idea if they've built a more user-friendly API or not, but this worked for my purposes.

    1. 1

      Oh, this is super close! It looks like the response I'm getting includes the numbers for each individual product (we have many in this store). Is there a way to get tweak the URL to get daily totals without manually adding it up?

      1. 2

        Not that I know of. Here's my best recollection of step 3 for me, based on looking at the data they send again.

        I believed I just copied the raw JSON data into my browser console, saved it as a variable like data and then got the totals with something like this (JavaScript):

        sumArrays = (a, b) => a.map((x, index) => x + b[index]);
        
        productIds = Object.keys(data.by_date.product.views)
        sales = productIds.map((x) => data.by_date.product.sales[x]).reduce(sumArrays)
        views = productIds.map((x) => data.by_date.product.views[x]).reduce(sumArrays)
        

        The dates are in there at the top level, too. I think mapped over them something like this:

        data.dates.map((x, i) => [x, views[i], sales[i]].join('\t')).join('\n')
        

        to get this format

        date TAB views TAB sales
        date TAB views TAB sales
        

        Then I copy-pasted that into a new .tsv file my spreadsheet could recognize. I was going to write a script to automate it or look at their api a bit more closely but I haven't really been using Gumroad the past couple of years so it wasn't worth it.

        1. 2

          Thanks for all of this!

  2. 1

    @sahil is there an easier way to do this?