简体   繁体   English

Data Studio社区连接器

[英]Data Studio Community Connector

I'm trying to pull keyword ranking data into Data Studio by creating a community connector. 我试图通过创建社区连接器将关键字排名数据拖入Data Studio。 The API method I'm using can be found here: 我正在使用的API方法可在以下位置找到:

https://www.rankranger.com/documentation/api-method-rank https://www.rankranger.com/documentation/api-method-rank

Essentially I'm trying to replicate the Google Code Labs tutorial as well as this similar script using a different API - however I'm unable to even connect to Data Studio when I try and publish via the manifest. 本质上,我正在尝试使用其他API复制Google Code Labs教程以及类似脚本 -但是,当我尝试通过清单进行发布时,我什至无法连接到Data Studio。

I was wondering whether anyone had any experience - or could tell me where I'm going wrong? 我想知道是否有人有经验-或可以告诉我我要去哪里错了?

// Get Config Parameters

function getConfig(request) {
  var config = {
    "configParams": [
      {
        "type": "INFO",
        "name": "welcomeMessage",
        "text": "Full instructions tbc"
      },
      {
        "type": "TEXTINPUT",
        "name": "apiKey",
        "displayName": "API Key 1",
        "helpText": "You'll be provided with this :)",
        "placeholder": "API Key"
      },
      {
        "type": "TEXTINPUT",
        "name": "campaignId",
        "displayName": "Campaign ID",
        "helpText": "We need to retrieve this through the API",
        "placeholder": "Campaign ID"
      },
      {
        "type": "TEXTINPUT",
        "name": "domain",
        "displayName": "Root Domain",
        "helpText": "The root domain of the site you want rankings for.",
        "placeholder": "root domain"
      }
    ],
    dateRangeRequired: true
  };
  return config;
}

// Set the schema for the fields we'll need the data for

var dataSchema = [
 {
    name: 'date',
    label: 'Date',
    description: 'Date of parsedResponse to select in YYYY-MM-DD',
    group: 'Date',
    dataType: 'STRING',
    semantics: {
      conceptType: 'DIMENSION',
      semanticType: 'YEAR_MONTH_DAY',
      semanticGroup: 'DATE'
    }
  },
  {
    name: 'url',
    label: 'Domain',
    dataType: 'STRING',
    semantics: {
    conceptType: 'DIMENSION'
    }
  },
  {
    name: 'lp',
    label: 'Landing Page',
    dataType: 'URL',
    semantics: {
      conceptType: 'DIMENSION'
    }
  },
  {
    name: 'keyword',
    label: 'Keyword',
    dataType: 'STRING',
    semantics: {
      conceptType: 'DIMENSION'
    }
  },
  {
    name: 'se',
    label: 'Search Engine',
    dataType: 'STRING',
    semantics: {
      conceptType: 'DIMENSION'
    }
  },
  {
    name: 'se_name',
    label: 'Sarch Engine Name',
    dataType: 'STRING',
    semantics: {
      conceptType: 'DIMENSION'
    }
  },
  {
    name: 'rank',
    label: 'Rank',
    dataType: 'NUMBER',
    semantics: {
      conceptType: 'METRIC',
      isReaggregatable: false
    }
  }
];

// Function to return the data schema

function getSchema(request) {
  return {schema: dataSchema};
}

// OAuth function that we don't need

function getAuthType() {
  var response = {
    "type": "NONE"
  };
  return response;
}

// Most important - the get data request

function getData(request) {
  // Create schema for requested fields
  var requestedSchema = request.fields.map(function (field) {
    for (var i = 0; i < dataSchema.length; i++) {
      if (dataSchema[i].name == field.name) {
        return dataSchema[i];
      }
    }
  });

    var url = [
    'https://www.rankranger.com/api/v2/?rank&key=',
    request.configParams.apiKey,
    '&start_date=',
    request.dateRange.startDate,
    '&end_date=',
    request.dateRange.endDate,
    '&campaign_id=',
    request.configParams.campaignId,
    '&domain=',
    request.configParams.domain,
    '&output=json'
  ];

  var response = UrlFetchApp.fetch(url.join(''));
  var parsedResponse = JSON.parse(response.getContentText());


  // Prepare the tabular data.
  var requestedData = parsedResponse.map(function(rankings) {
    var values = [];
    // Provide values in the order defined by the schema.
    dataSchema.forEach(function(field) {
      switch(field.name) {
          case 'date':
            values.push(rankings.date.replace(/-/g, ''));
            break;
          case 'url':
            values.push(rankings.url);
            break;
          case 'lp':
            values.push(rankings.lp);
            break;
          case 'keyword':
            values.push(rankings.keyword);
            break;
          case 'se':
            values.push(rankings.se);
            break;
          case 'se_name':
            values.push(rankings.se_name);
            break;
          case 'rank':
            values.push(rankings.rank || 101);
            break;
      }
    });
    return {values: values};
  });
    // return the data for the request
    return {
    schema: requestedSchema,
    rows: requestedData
  };
}

You aren't supposed to use quotes for "configParams". 您不应该在“ configParams”中使用引号。 It should look like that; 它看起来应该像这样;

var config = { configParams: [ { "type": "INFO", "name": "welcomeMessage", "text": "Full instructions tbc" }, { "type": "TEXTINPUT", "name": "apiKey", "displayName": "STAT API Key", "helpText": "You'll be provided with this :)", "placeholder": "STAT API Key" }, { "type": "TEXTINPUT", "name": "siteId", "displayName": "STAT Site ID", "helpText": "We need to retrieve this through the API", "placeholder": "STAT Site ID" }, { "type": "TEXTINPUT", "name": "siteName", "displayName": "STAT Site subdomain", "helpText": "The subdomain of your stat login url.", "placeholder": "STAT Site subdomain" } ] };

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

相关问题 如何开始为 Data Studio 构建社区连接器? - How do I get started with building a Community Connector for Data Studio? Google 数据工作室社区连接器本地开发工具返回“getSystemErrorName 不是函数”错误 - Google data studio community connector local development tool returns “getSystemErrorName is not a function” error 数据洞察连接器:运行承诺? - Data Studio connector: Running a promise? Google Data Studio 连接器中的 UrlFetchApp 异常 - UrlFetchApp exception in Google Data Studio connector Google Data Studio连接器和应用脚本 - Google Data Studio Connector and App Scripts 在 Google 数据工作室社区连接器中对嵌套数据建模 - Modeling nested data in Google data studio community connectors Google Data Studio - 自定义连接器 - 获取数据解析 json - Google Data Studio - Custom Connector - Get Data parsing json 如何在社区连接器中将字段设置为日期? - How to set a field as a date in a Community Connector? 如何通过 Data Studio 社区连接器对第三方服务使用用户/通行证身份验证方法? - How can I use User/Pass authentication method for a third party service with Data Studio Community Connectors? 将 d3.js Trend Chart (Area + Line) 集成为数据工作室社区可视化 - Integrating d3.js Trend Chart (Area + Line) as data studio community visualisation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM