简体   繁体   English

在 DataStudio 的自定义连接器中过滤数据

[英]Filtering data in custom connector for DataStudio

I'm trying to create a custom datastudio connector that connect to WooCommerce rest API. I want to differentiate between orders placed by a registered user and orders placed by a guest user .我正在尝试创建一个连接到 WooCommerce rest API 的自定义datastudio连接器。我想区分registered user下的订单和guest user下的订单。

The WooCommerce API gives me the custumer_id field, if the customer_id = 0 , the order was placed by a guest , otherwise the user is registered . WooCommerce API 给我custumer_id字段,如果customer_id = 0 ,订单是由guest下的,否则user is registered

I followed the google data studio tutorial: https://developers.google.com/datastudio/connector/get-started我遵循了谷歌数据工作室教程: https://developers.google.com/datastudio/connector/get-started

And this is my responseToRow function:这是我的responseToRow function:

/**
Parse the response data given the required fields of the config
@return the parsed data
*/
function responseToRows(requestedFields, response) {
  // Transform parsed data and filter for requested fields
  return response.map(function(dailyDownload) {
    var row = [];
    requestedFields.asArray().forEach(function (field) {
      switch (field.getId()) {
        case 'id_order':
          return row.push(dailyDownload.id);
        case 'total':
          return row.push(dailyDownload.total);
        case 'date_created':
          return row.push(dailyDownload.date_created);
        case 'registered_user' :
          if(parseInt(dailyDownload.customer_id) > 0)
            return row.push(dailyDownload.customer_id);
        case 'guest_user' :
          if(parseInt(dailyDownload.customer_id) == 0)
            return row.push(dailyDownload.customer_id);
        default:
          return row.push('');
      }
    });
    return { values: row };
  });
}

The function is similar to the one given in the tutorial, the others fields works fine. function 与教程中给出的类似,其他字段工作正常。 I'm just returning when the customer_id is different of 0. It seem to work, but I get null values when the condition doesn't hold.当 customer_id 不同于 0 时,我才返回。它似乎有效,但当条件不成立时,我得到 null 值。

我的数据工作室报告的屏幕截图

I would like to remove the null values, having only the orders when the customer_id was 0 on the right and the same for the complement on the left part.我想删除 null 值,只有当customer_id为 0 时右侧的订单和左侧补码相同的订单。

Thanks for the help谢谢您的帮助

I would try it like that after filling the row array:我会在填充行数组后尝试这样做:

row.forEach((element, index) => {
   if(element.guest_user == null){
      // To remove the row-entry with guest_user==null
      row[index].slice(); 
   }
})

And if you don't want to remove the entries from the array just create a new array and use newArray.push(element);如果您不想从数组中删除条目,只需创建一个新数组并使用 newArray.push(element); to copy the null ones into it.将 null 复制到其中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Data Studio 自定义连接器字段数量错误 - Data Studio Custom Connector wrong amount of fields 自己的连接器的自定义数据新鲜度选项 - Custom data freshness options for own connector Google Data Studio - 自定义连接器 - 获取数据解析 json - Google Data Studio - Custom Connector - Get Data parsing json 使用DataStudio为BigQuery中的自定义查询指定日期范围,其中日期范围影响查询中的运算符 - Use DataStudio to specify the date range for a custom query in BigQuery, where the date range influences operators in the query 在 AWS Glue ETL 脚本中使用自定义连接器 - Using custom connector in AWS Glue ETL script 我想知道一种将“yyyy-mm-dd”日期类型数据链接到 DataStudio 的有效方法 - I want to know an efficient way to link "yyyy-mm-dd" date type data to DataStudio Heroku Postgresql 与 Google Datastudio - Heroku Postgresql with Google Datastudio 在 Azure 逻辑应用(标准)中找不到自定义连接器 - Custom connector not found in Azure logic app(Standard) Amplify AppSync:自定义排序和分页过滤 - Amplify AppSync: custom sorting and filtering with pagination 过滤数据在 Firestore android 中不起作用 - Filtering data is not working in firestore android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM