Search code examples
google-analyticsgoogle-analytics-api

GA API - Getting Product Info Associated to Sku


I'm running into an issue that I'm hoping someone might know how to resolve. In the reporting api, I can get information based on a sku. Something like so:

  {
    'reportRequests': [{
      'viewId': VIEW_ID,
      'dateRanges': [{'startDate': '7daysAgo', 'endDate': 'today'}],
      'metrics': [
        {"expression": "ga:productDetailViews"},
        {"expression": "ga:itemQuantity"},
        {"expression": "ga:uniquePurchases"},
        {"expression": "ga:itemRevenue"}
      ],
      'dimensions': [{'name':'ga:productSku'}]
      }
    ]
  }

This is great for getting the data tied to a sku, but I was wondering if there is a way to get additional product information for each sku rather than metric information. For example, given a set of skus, I'd like to see the category hierarchy (section, category, subcategory) as well as the product name:

SKU, Name,   Section,Category,  Subcategory
1,   Blah,   Shoes,  Basketball,
2,   Another,Shoes,  Soccer,    Mens
...

Given that information like this is all correlated on a page when sent from a website, I don't see why this shouldn't be possible.

ga('ec:addProduct', {
    'id': '1',
    'name': 'Blah',
    'category': 'Shoes/Basketball',
});

Adobe has something similar with their Saint Classifications and I was hoping it would be something possible to get out of GA. I can't seem to find anything like this across any of the apis, so am hoping someone can point me in the right direction!


Solution

  • As you look to have specified categories with the correct '/' delimiter you can use the dimension ga:productCategoryLevelXX, you do need to have at least one metric in your request but you could do something like

      {
        'reportRequests': [{
          'viewId': VIEW_ID,
          'dateRanges': [{'startDate': '7daysAgo', 'endDate': 'today'}],
          'metrics': [{"expression": "ga:productDetailViews"}],
          'dimensions': [
            {"expression": "ga:productSku"},
            {"expression": "ga:productCategoryLevel1"},
            {"expression": "ga:productCategoryLevel2"},
            {"expression": "ga:productCategoryLevel3"}
          ]
        ]
      }