# Direct Link

You can share any deployment of your Community Connector with a link. When a
user follows the link, it will take them directly to Data Studio with your
connector selected.

To get a direct link for your community connector, follow these steps:

1. Navigate to [Apps Scripts](https://script.google.com/home) and open the project of the Community Connector to share. Click **Deploy \> Manage Deployments**.
2. Click the *Active* deployment to share. Under *Data Studio Add-on URL* , a direct link to Data Studio for the selected deployment is displayed, click **Copy** . Alternatively, under *Deployment ID* click **Copy** and append the copied Deployment ID to the following URL to form a direct link:

   ```
   https://datastudio.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.

## Preconfigure a direct link

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.

### Create a preconfigured direct Link

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](https://developers.google.com/data-studio/connector/reference.md.txt#getconfig).
  - `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](https://developers.google.com/data-studio/connector/report-templates.md.txt#how_to_add_the_report_template_to_the_connector_manifest) for the value to use.

### Example

The following example illustrates how to create a direct link to the
[StackOverflow Questions](https://github.com/googledatastudio/community-connectors/tree/master/stackoverflow-questions) community connector. The direct link
pre-populates the connector configuration to use the `data-studio` tag on
Stack Overflow.

> [!CAUTION]
> **Caution:** If a connector hasn't been authorized, then pre-populating does not work. Users will need to authorize the connector, then try the link again.

#### Step 1: Create the config JSON

The keys for the config JSON are the names of each configuration item. For the
[Stack Overflow config](https://github.com/googledatastudio/community-connectors/blob/c214a7a3cdfe75323502fc65628d483b8d15ec98/stackoverflow-questions/main.js#L41-L82), these names are `tagged`, `pagesize`, and
`sort`.   

**JSON before encoding**

```json
{
    "tagged": "data-studio",
    "pagesize": 25,
    "sort": "activity"
}
```

#### Step 2: Encode the URL

After the configuration JSON is created, URL encode the object. An easy option
is to use the [`encodeURIComponent`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) JavaScript function.

**Encoding Url**

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

The result is the following encoded string:

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

#### Step 3: Build the URL

The following code builds the direct link. Note that you will need your
connector's Deployment ID to build the URL.
data-studio/links.gs [View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/data-studio/links.gs)

```javascript
// These variables should be filled in as necessary for your connector.
let configJSON;
let templateId;
let deploymentId;

const 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}`;
```

> [!NOTE]
> **Note:** The `reportTemplateId` is optional, but included in the above snippet. If you aren't using a `reportTemplateId`, remove that part of the code.

This returns the following encoded URL, a pre-populated direct link for the
connector:

```html
https://datastudio.google.com/datasources/create?connectorConfig=%7B%22tagged%22%3A%22data-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
```