BETA: Working with dynamic data sources

A dynamic data source is a data source which uses one or more variables in its query instead of hard-coded values, thereby enabling the ability to dynamically retrieve data.

To demonstrate, these instructions use a Google Analytics data source as an example.

Note: You cannot reconfigure or duplicate an existing non-dynamic data source. Dynamic data sources must be created from scratch.

Step 1: Creating a variable with a value

In the Klip editor, create a variable for the dynamic data source to use. 

    1. Go to Library and select the Klips tab.
    2. Click Build a New Klip, select the Value component, then select Don't use a data source
    3. In the formula editor, select Create New Variable... from the Advanced Tools menu, type a Variable Name and a Value. For example, gaID and 1234567.


Note: 

      the variable used in a dynamic data source must be set to a value that will return valid results when used in the data source query.



  1. Click Create Variable.
  2. Repeat for any additional variables you might want to set up.

It is not necessary to Save the Klip.

Step 2: Setting up the data source URL

Set up the variable in a data source URL.

    1. Go to Library and select the Data Sources tab.
    2. Click Create a New Data Source, select the Google Analytics option and authenticate with Google Analytics.
    3. From the New Data Source page, perform the following tasks.
      1. Create your Google Analytics query.
      2. Switch to Advanced mode.
      3. In the Query URI, type the variable in place of a hard-coded value, using the format {props.gaID}. 

 

        For example, in  



https://www.googleapis.com/analytics/v3/data/ga?ids=ga:1234567&start-date=date.startOfYear&end-date={date.today}

replace 1234567 with {props.gaID} where the gaID variable is assigned a value that will return valid results when used in the data source query

https://www.googleapis.com/analytics/v3/data/ga?ids=ga:{props.gaID}&start-date=date.startOfYear&end-date={date.today}

  1. Click Get Data, then click Continue.
  2. Name and Save the data source.

Using the dynamic data source in a Klip

A user input control component and a table component demonstrate how to use a Google Analytics dynamic data source in a Klip.

Build a user input control component:

  1. Go to Library and select the Klips tab.
  2. Click  Build a New Klip, select the User Input Control component and select Don't use a data source.
  3. Select the Properties tab.
  4. Select the Values subcomponent and create an ARRAY with a list of Google Analytic IDs
    1. Type a Control Label.
    2. Set Control Type to Drop-Down List.
    3. Set Value to the variable you created earlier. For example, gaID.
  5. Select the Values subcomponent and either create an ARRAY with a list of Google Analytic IDs or select a list of Google Analytic IDs from a data source (typically a spreadsheet).

Build a table component:

  1. Go to Library and select the Klips tab.
  2. Click Build a New Klip and select the Table component.
  3. Select Use an existing data source from the library and select your dynamic data source.
  4. In the Klip editor:
    1. For Column 1 select the variable, gaID. Format as Text.
    2. For Column 2 select Column B (ga:visitors) from the dynamic data source and wrap with the SLICE function to remove the row header, Format as Number.
    3. Name the Columns and Save the Klip.

When a Google Analytic ID is selected from the user input control, a dynamic data source instance is created and the table automatically responds to display the data for the Google Analytic ID selected.

Learn more:

Now that you know more about dynamic data sources, check out the following: