直接連結

你可以利用連結分享「社群連接器」的任何部署作業。如果 使用者點選連結後,系統就會將他們直接帶往 Looker Studio,並提供您的 已選取連接器。

如要取得社群連接器的直接連結,請按照下列步驟操作:

  1. 前往 Apps Scripts 並開啟社群專案 要共用的連接器。按一下「部署」>「部署」管理部署作業
  2. 點選「Active」部署作業進行共用。在「Looker Studio 外掛程式網址」下方, 畫面上隨即會顯示所選部署作業的 Looker Studio 直接連結,按一下 「複製」。或者,在「部署作業 ID」下方,按一下「複製」並附加 將 Deployment ID 複製到以下網址,建立直接連結:
    https://lookerstudio.google.com/datasources/create?connectorId=DEPLOYMENT_ID
  3. The direct link can be shared with users. For example, send it via email, post it on a website, blog, social media, etc.

If you know the configuration values that your users will want ahead of time, you can provide additional query parameters to pre-populate the connector configuration. The pre-populated configuration can still be modified by users.

To create a preconfigured direct link, add the following optional query parameters:

  • connectorConfig - A URL encoded JSON string containing key-value pairs to use to pre-populate the connector configuration.

    • Key names must match the parameter names defined in the connector config.
    • TEXTINPUT, TEXTAREA, and SELECT_SINGLE values should be strings.
    • CHECKBOX values should be a boolean.
    • SELECT_MULTIPLE values should be an array of strings.
  • reportTemplateId - An identifier for the default reporting template to use for the connector. If a default template is set in the connector manifest, this value will override the manifest. See How To Add The Report Template for the value to use.

Example

The following example illustrates how to create a direct link to the StackOverflow Questions community connector. The direct link pre-populates the connector configuration to use the looker-studio tag on Stack Overflow.

Step 1: Create the config JSON

The keys for the config JSON are the names of each configuration item. For the Stack Overflow config, these names are tagged, pagesize, and sort.

JSON before encoding

{
    "tagged": "looker-studio",
    "pagesize": 25,
    "sort": "activity"
}

步驟 2:對網址進行編碼

建立設定 JSON 後,網址會對物件進行網址編碼。方便的選項 是使用 encodeURIComponent JavaScript 函式。

編碼網址

// get a reference to the jsonConfig
var jsonConfig;
var encoded = encodeURIComponent(jsonConfig);

結果是以下編碼字串:

"%7B%22tagged%22%3A%22looker-studio%22%2C%22pagesize%22%3A%2225%22%2C%22sort%22%3A%22activity%22%7D"

步驟 3:建立網址

下方程式碼可建構直接連結。請注意,您需要 用於建立網址的連接器 Deployment ID。

data-studio/links.gs
// These variables should be filled in as necessary for your connector.
var configJSON;
var templateId;
var deploymentId;

var params = [];

const jsonString = JSON.stringify(configJSON);
const encoded = encodeURIComponent(jsonString);
params.push('connectorConfig=' + encoded);

params.push('reportTemplateId=' + templateId);

params.push('connectorId=' + deploymentId);

const joinedParams = params.join('&');
const URL = 'https://datastudio.google.com/datasources/create?' + joinedParams;

這會傳回以下編碼網址,也就是 連接器:

https://lookerstudio.google.com/datasources/create?connectorConfig=%7B%22tagged%22%3A%22looker-studio%22%2C%22pagesize%22%3A%2225%22%2C%22sort%22%3A%22activity%22%7D&reportTemplateId=1lR9CGfx3uyQp6oz7oAgA1rsqZViA-IQs&connectorId=AKfycbwGMj-oe532y-NEbMHo-KLUCEz0EEGOZj-3lhEgw7q65-hs-T_F9B3Qjw