Launch your Data Commons

Overview

When you are ready to launch your site to external traffic, there are many tasks you will need to perform, including:

Improve database performance

We recommend that you use a caching layer to improve the performance of your database. We recommend Google Cloud Redis Memorystore, a fully managed solution, which will boost the performance of both natural-language searches and regular database lookups in your site. Redis Memorystore runs as a standalone instance in a Google-managed virtual private cloud (VPC), and connects to your VPC network (“default” or otherwise) via direct peering. Your Cloud Run service connects to the instance using a VPC connector. We recommend that you use a caching layer to improve the performance of your database. We recommend Google Cloud Redis Memorystore, a fully managed solution, which will boost the performance of both natural-language searches and regular database lookups in your site. Redis Memorystore runs as a standalone instance in a Google-managed virtual private cloud (VPC), and connects to your VPC network (“default” or otherwise) via direct peering. Your Cloud Run service connects to the instance using a VPC connector.

In the following procedures, we show you how to create a Redis instance that connects to your project’s “default” VPC network.

Step 1: Create the Redis instance

The following is a sample configuration that you can tune as needed. For additional information, see Create and manage Redis instances. The following is a sample configuration that you can tune as needed. For additional information, see Create and manage Redis instances.

  1. Go to https://console.cloud.google.com/memorystore/redis/instances for your project.
  2. Go to https://console.cloud.google.com/memorystore/redis/instances for your project.
  3. Select the Redis tab and click Create Instance.
  4. If prompted to enable the Redis API server, accept.
  5. Name your instance.
  6. Under Tier Selection, select Basic.
  7. Set the Capacity field to 2 GB.
  8. Under Region and zonal availability, set the region to be the same as your Cloud SQL database.
  9. Under Set up connection > Network, select default as the network.
  10. Click Create.

Step 2: Set the environment variable

  1. When the Redis instance is created above, go to the Instances > Redis tab, look up your instance and note the Primary Endpoint IP address.
  2. In custom_dc/env.list, set the value of the REDIS_HOST option to the IP address.

Step 3: Create the VPC connector

  1. Go to https://console.cloud.google.com/networking/connectors/list for your instance.
  2. Go to https://console.cloud.google.com/networking/connectors/list for your instance.
  3. If you are prompted to enable the VPC Access API, accept.
  4. In the Serverless VPC Access screen, click Create Connector.
  5. Name the connector.
  6. Under Region, select the region you specified for Redis instance in the first step.
  7. In the Network field, select default.
  8. Under Subnet, select Custom IP Range.
  9. In the IP Range field, enter a valid IP range; for example, 10.9.0.0.
  10. Click Create.

For additional information, see Serverless VPC Access. For additional information, see Serverless VPC Access.

Step 4: Configure your Cloud Run service to connect to the VPC

  1. In the Cloud Console, go to the Cloud Run service from which you are serving your app.
  2. Click Edit & Deploy New Revision.
  3. Click the Networking tab and enable Connect to a VPC for outbound traffic.
  4. Enable Use Serverless VPC Access connectors.
  5. From the Network field, select the connector you created in step 3.
  6. Click Deploy.

Step 5: Verify that everything is working

To verify that your Cloud Run service is using the connector:

  1. Go to the Service details page for your service
  2. Click the Networking tab. Under VPC, you should see your connector listed.

To verify that traffic is hitting the cache:

  1. Run some queries against your running Cloud Run service.
  2. In the Cloud Console, go to the Memorystore page and select Redis instance.
  3. Under Instance Functions, click Monitoring.
  4. Scroll to the Cache Hit Ratio graph. You should see a significant percentage of your traffic hitting the cache.

Add Google Analytics reporting

Google Analytics provides detailed reports on user engagement with your site. In addition, Data Commons provides a number of custom parameters you can use to report on specific attributes of a Data Commons site such as, search queries, specific page views, etc.

Enable Analytics tracking

  1. If you don’t already have a Google Analytics account, create one, following the procedures in Set up Analytics for a website and/or app. Record the Analytics tag ID assigned to your account.
  2. Go to the Cloud Console for your Cloud Run service, and click Edit & deploy new revision.
  3. Expand Variables and secrets and click Add new variable.
  4. Add the name GOOGLE_ANALYTICS_TAG_ID and in the value field, type in your tag ID.
  5. Click Deploy to redeploy the service. Data collection will take a day or two to start and begin showing up in your reports.

Report on custom dimensions

Data Commons exports many Google Analytics custom events and parameters, to allow Data Commons-specific features to be logged, such as search queries, specific page views, etc. You can use these to create custom reports and explorations. The full set is defined in website/static/js/shared/ga_events.ts. Before you can get reports on them, you need to create custom dimensions from them.

To create a custom dimension for a Data Commons custom event:

  1. In the Google Analytics dashboard for your account, go to the Admin page.
  2. Select Data display > Custom definitions.
  3. Click Create custom dimension.
  4. Keep the Scope as Event and click the Event parameter > Select event parameter drop-down to see the list of custom event parameters.

    Custom parameters

  5. Select the parameter you need, for example, query.
  6. Add a dimension name and description. These can be anything you want but the name should be meaningful as it will show up in reports; for example, Search query.
  7. When done, click Save.
  8. Select Data display > Events and you should see a number of new custom events that have been added to your account.

To create a report based on a custom event:

  1. In the Google Analytics dashboard for your account, go to the Explore page and select Blank - create a new exploration.
  2. Select Variables > Dimensions > + to open the Select dimensions window.
  3. Select the Custom, select the dimension you want, for example, Search query, and click Import.

    Custom parameters

  4. Select Variables > Metrics > + to open the Select metrics window.
  5. Select the relevant metric you want, such as users, sessions, or views, etc. and click Import.
  6. Select Settings > Rows > Drop or select dimension and from the drop-down menu, select the dimension you want, such as Search query.
  7. Select Settings > Values > Drop or select metric and from the drop-down menu, select the metric of interest, such as users, sessions, views, etc.
  8. Edit any other settings you like and name the report. For the first 48 hours you will see (not set) for the first row. Afterwards, rows will be populated with real values.

Custom exploration