Setting up product analytics in Snowflake

Overview

This topic explains how to set up LaunchDarkly product analytics in Snowflake.

To set up product analytics, you must first connect LaunchDarkly’s Snowflake Native Product Analytics integration to import event and other data to LaunchDarkly. To do this, you provide some information to connect your Snowflake account to LaunchDarkly.

Prerequisites

Before completing this procedure, you must have the following prerequisites:

  • You should be tracking event data in your application
  • An active Snowflake account with the SECURITYADMIN and SYSADMIN privileges
  • Access to Snowflake

Set up product analytics with Snowflake

There are two ways to set up product analytics with Snowflake:

  • Using the Snowflake Data Export destination
  • Using a third-party customer data platform (CDP) to import your own events

Using the Snowflake Data Export destination

To use LaunchDarkly product analytics, you must first enable LaunchDarkly’s Snowflake Native Product Analytics integration. Here’s how:

  1. Click Product analytics in the left navigation, or find it by searching “Snowflake product analytics” on the Integrations page.
  2. Click Configure. The “Configure Snowflake Product Analytics” menu opens.
  3. Click Manage integration. The “Configure Snowflake Native Product Analytics” menu opens.
  4. Choose Using LaunchDarkly SDK and click Next step. If you have not yet configured Data Export, you will be prompted to do so. Then, the “Configure Snowflake Native Product Analytics” menu opens.

The Configure Snowflake Product Analytics menu.

The Configure Snowflake Product Analytics menu.
  1. Enter a human-readable Name.
  2. Enter your Snowflake account URL. You can find this in Snowflake’s “Account” menu, in the “Account/Server URL” field.

After you complete the steps above, LaunchDarkly generates a SQL script to connect your Snowflake account to LaunchDarkly. In the “Configure Snowflake Native Product Analytics” menu:

  1. Copy the script and paste it into a new worksheet in your Snowflake account.
  2. Run the script in Snowflake. When it completes, return to LaunchDarkly.
  3. Read the “Integration Terms and Conditions,” and then select the checkbox to acknowledge them.
  4. Click Save configuration. A confirmation message appears at the top of the screen when configuration completes successfully.

Using a third-party customer data platform (CDP) to import your own events

To use LaunchDarkly product analytics, you can also import your own events from a third-party customer data platform (CDP). Here’s how:

  1. Click Product analytics in the left navigation, or find it by searching “Snowflake product analytics” on the Integrations page.
  2. Click Configure. The “Configure Snowflake Product Analytics” menu opens.
  3. Click Manage integration. The “Configure Snowflake Native Product Analytics” menu opens.
  4. Choose Use CDP/Custom SDK and click Next step. The “Configure Snowflake Warehouse” menu opens.
  5. Enter a human-readable Name.
  6. Enter your Snowflake account URL. You can find this in Snowflake’s “Account” menu, in the “Account/Server URL” field. This generates a public_key and project_env_key. Save these values for use in the script below.

The Configure Snowflake Product Analytics menu.

The Configure Snowflake Product Analytics menu.

Configure your custom SDK or CDP to send events to a table in your Snowflake project. These events must be transformed to match LaunchDarkly’s required schema in an ALLEVENTS table or a view. Here is the structure to use:

Column nameTypeDescription
device_idSTRINGUnique identifier for the device
user_idSTRINGUnique identifier for the user
event_nameSTRINGName of tracked event
event_idSTRINGUnique identifier for the event
server_tsTIMESTAMPServer-side timestamp of when the event was received
device_tsTIMESTAMPClient-side timestamp of when the event occurred
propertiesJSONEvent-specific properties of a JSON object
user_propertiesJSONUser-specific properties of a JSON object

Now, use the code below to configure your CDP or custom SDK to connect to LaunchDarkly product analytics.

Configuration script
1-- Setting up the warehouse, database, schema, roles, user and such.
2-- the events table schema we expect
3
4begin;
5-- Enter project environment key
6set project_env_key = 'PROJECT_ENV_KEY_GENERATED_IN_PROCEDURE_ABOVE';
7-- ===== System Setup Variables (Do not modify) =====
8set warehouse_name = 'LD_PRODUCT_ANALYTICS_WH'; -- Uppercase required
9set database_name = 'LD_PRODUCT_ANALYTICS'; -- Uppercase required
10set role_name = 'LD_PRODUCT_ANALYTICS_ROLE'; -- Uppercase required
11set schema_name = 'PRODUCT_ANALYTICS_'|| $project_env_key;
12set user_name = 'LD_PRODUCT_ANALYTICS_USER_'|| $project_env_key;
13-- ===== Warehouse Setup =====
14use role sysadmin;
15create warehouse if not exists identifier($warehouse_name)
16 warehouse_size = medium
17 warehouse_type = standard
18 auto_suspend = 60
19 auto_resume = true
20 initially_suspended = true;
21-- ===== Database Setup =====
22create database if not exists identifier($database_name);
23-- ===== Role Setup =====
24use role securityadmin;
25create role if not exists identifier($role_name);
26grant role identifier($role_name) to role SYSADMIN;
27-- ===== Permissions: Warehouse & Database =====
28use role sysadmin;
29grant usage, operate
30 on warehouse identifier($warehouse_name)
31 to role identifier($role_name);
32grant monitor, usage
33 on database identifier($database_name)
34 to role identifier($role_name);
35grant create schema
36 on database identifier($database_name)
37 to role identifier($role_name);
38grant usage
39 on all schemas in database identifier($database_name)
40 to role identifier($role_name);
41grant usage
42 on future schemas in database identifier($database_name)
43 to role identifier($role_name);
44grant create table
45 on all schemas in database identifier($database_name)
46 to role identifier($role_name);
47grant create table
48 on future schemas in database identifier($database_name)
49 to role identifier($role_name);
50grant select
51 on all tables in database identifier($database_name)
52 to role identifier($role_name);
53grant select
54 on future tables in database identifier($database_name)
55 to role identifier($role_name);
56grant select
57 on all views in database identifier($database_name)
58 to role identifier($role_name);
59grant select
60 on future views in database identifier($database_name)
61 to role identifier($role_name);
62-- ===== Schema Setup =====
63use database identifier($database_name);
64create schema if not exists identifier($schema_name);
65grant usage, create table, create view
66 on schema identifier($schema_name)
67 to role identifier($role_name);
68grant create procedure, create task, create stream, create function
69 on schema identifier($schema_name)
70 to role identifier($role_name);
71grant operate
72 on future tasks in schema identifier($schema_name)
73 to role identifier($role_name);
74grant execute task on account
75 to role identifier($role_name);
76-- ===== User Setup =====
77use role securityadmin;
78create user if not exists identifier($user_name);
79alter user identifier($user_name)
80 set default_role = $role_name,
81 default_warehouse = $warehouse_name,
82 QUOTED_IDENTIFIERS_IGNORE_CASE = false;
83grant role identifier($role_name)
84 to user identifier($user_name);
85-- ===== Set Public Key =====
86alter user identifier($user_name)
87 set rsa_public_key=$$
88PASTE_PUBLIC_KEY_GENERATED_IN_PROCEDURE_ABOVE
89$$;
90commit;

Use the dataset you created in the previous procedure as the destination for the ALLEVENTS table.

After you create the ALLEVENTS table, run the following commands to enable change tracking:

1-- ==== Run this only after creating the ALLEVENTS table in the schema ==== --
2-- This assumes the ALLEVENTS table already exists --
3-- ==== Change role to LD_PRODUCT_ANALYTICS_ROLE to run this ==== --
4
5use role identifier($role_name);
6alter table ALLEVENTS set change_tracking = true;

If you have created an ALLEVENTS view instead of a table, then run the following commands to enable change tracking:

1-- ==== Run this only after creating the ALLEVENTS view in the schema ==== --
2-- This assumes the ALLEVENTS view already exists --
3-- ==== Change role to LD_PRODUCT_ANALYTICS_ROLE to run this ==== --
4
5use role identifier($role_name);
6alter view ALLEVENTS set change_tracking = true;

In the “Configure Snowflake warehouse” menu:

  1. Return to the “Configure Snowflake Native Product Analytics” in LaunchDarkly.
  2. Read the “Integration Terms and Conditions,” and then select the checkbox to acknowledge them.
  3. Click Save configuration. A confirmation message appears at the top of the screen when configuration completes successfully.

After you complete the setup steps, the landing page on the Product analytics screen in LaunchDarkly will update to show a “Waiting for data…” status. Events and other information will begin to populate the screen within 15 minutes. Events from the last 30 days will be available within an hour. Load time varies based on the volume of data you’re importing from Snowflake.

To verify that data is loading, refresh the page. The Dashboards tab will not have any information in it until you create a dashboard, but you can confirm that setup was successful by checking the Events and Attributes tabs. After the import completes, both of those tabs display pre-populated data.

After the event data appears, you will be able to access different aspects of the product analytics UI.

To learn more, read Dashboards, Events, Cohorts, and Attributes.