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:
- Configure your Cloud Service to serve external traffic, over SSL. GCP offers many options for this; see Mapping a domain using a global external Application Load Balancer.
- Optionally, restrict access to your service; see Custom audiences (services).
- Optionally, add a caching layer to improve performance. We have provided specific procedures to set up a Redis Memorystore in Improve database performance.
- Optionally, add Google Analytics to track your website’s usage. Procedures for configuring Google Analytics support are in Add Google Analytics tracking.
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.
- Go to https://console.cloud.google.com/memorystore/redis/instances for your project.
- Go to https://console.cloud.google.com/memorystore/redis/instances for your project.
- Select the Redis tab and click Create Instance.
- If prompted to enable the Redis API server, accept.
- Name your instance.
- Under Tier Selection, select Basic.
- Set the Capacity field to 2 GB.
- Under Region and zonal availability, set the region to be the same as your Cloud SQL database.
- Under Set up connection > Network, select default as the network.
- Click Create.
Step 2: Set the environment variable
- When the Redis instance is created above, go to the Instances > Redis tab, look up your instance and note the Primary Endpoint IP address.
- In
custom_dc/env.list
, set the value of theREDIS_HOST
option to the IP address.
Step 3: Create the VPC connector
- Go to https://console.cloud.google.com/networking/connectors/list for your instance.
- Go to https://console.cloud.google.com/networking/connectors/list for your instance.
- If you are prompted to enable the VPC Access API, accept.
- In the Serverless VPC Access screen, click Create Connector.
- Name the connector.
- Under Region, select the region you specified for Redis instance in the first step.
- In the Network field, select default.
- Under Subnet, select Custom IP Range.
- In the IP Range field, enter a valid IP range; for example,
10.9.0.0
. - 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
- In the Cloud Console, go to the Cloud Run service from which you are serving your app.
- Click Edit & Deploy New Revision.
- Click the Networking tab and enable Connect to a VPC for outbound traffic.
- Enable Use Serverless VPC Access connectors.
- From the Network field, select the connector you created in step 3.
- Click Deploy.
Step 5: Verify that everything is working
To verify that your Cloud Run service is using the connector:
- Go to the Service details page for your service
- Click the Networking tab. Under VPC, you should see your connector listed.
To verify that traffic is hitting the cache:
- Run some queries against your running Cloud Run service.
- In the Cloud Console, go to the Memorystore page and select Redis instance.
- Under Instance Functions, click Monitoring.
- 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
- 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.
- Go to the Cloud Console for your Cloud Run service, and click Edit & deploy new revision.
- Expand Variables and secrets and click Add new variable.
- Add the name
GOOGLE_ANALYTICS_TAG_ID
and in the value field, type in your tag ID. - 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:
- In the Google Analytics dashboard for your account, go to the Admin page.
- Select Data display > Custom definitions.
- Click Create custom dimension.
-
Keep the Scope as Event and click the Event parameter > Select event parameter drop-down to see the list of custom event parameters.
- Select the parameter you need, for example, query.
- 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
. - When done, click Save.
- 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:
- In the Google Analytics dashboard for your account, go to the Explore page and select Blank - create a new exploration.
- Select Variables > Dimensions > + to open the Select dimensions window.
-
Select the Custom, select the dimension you want, for example, Search query, and click Import.
- Select Variables > Metrics > + to open the Select metrics window.
- Select the relevant metric you want, such as users, sessions, or views, etc. and click Import.
- Select Settings > Rows > Drop or select dimension and from the drop-down menu, select the dimension you want, such as Search query.
- Select Settings > Values > Drop or select metric and from the drop-down menu, select the metric of interest, such as users, sessions, views, etc.
- 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.
Page last updated: November 27, 2024 • Send feedback about this page