Example of join custom script
This reference explains how to join data extracts from multiple datastreams of the same type. This guide uses two Google Analytics datastreams as an example.
Introduction
To combine data from two or more datastreams, use the join custom script enrichment. You can combine the data from a number of datastreams, either of the same or different types. For example, you can join data from a Facebook Ads datastream and a Google Ads datastream. The datastreams to be joined must share a common data point (this is often a column in all of the datastreams to join that contains the identical data).
This guide only explains one specific use case of the join method. The example in this guide requires you to create two Google Analytics datastreams that have a different set of metrics but share the same set of dimensions. Once the datastreams are created, this guide will then outline how to create the join enrichment.
Creating Google Analytics datastreams
To add two Google Analytics datastreams, follow these steps:
-
Select the workspace you work with in Adverity and then, in the , click Datastreams.
-
In the top right corner, click + Create datastream.
-
Search for and click Google Analytics.
-
Click Next.
-
Choose one of the following options:
-
If you already have an Google Analytics, click the existing .
to -
To set up the new Setup a new .
with your own login credentials, click -
To ask someone else to set up the new Send an access request. In the Email field, write the email address of the person you want to ask to authorize the new . (Optional) Customize the message and set notification preferences. Click Send access request.
, click
-
-
Click Next.
-
Click Custom configuration.
-
Click Next.
-
Rename your datastream to Google Analytics Test 1.
-
In Metrics, make sure the following fields are selected:
-
ga:newUsers
-
ga:sessions
-
ga:bounces
-
ga:pageviews
-
-
Click Next.
-
To assign destinations to your datastream, select their checkboxes. For more information on destinations and their configuration settings, see Introduction to transferring data.
-
Click Next.
-
In the Choose date range field, click Yesterday.
-
Click Run Fetch.
As a result, you have created one of the two Google Analytics datastreams.
To create the second Google Analytics datastream, repeat the previous procedure but change the following steps:
-
In step 9, rename your datastream to Google Analytics Test 2.
-
In step 10, remove the default metrics and select the following:
-
ga:users
-
ga:transactions
-
ga:totalEvents
-
As a result, you have created the second Google Analytics datastream to join with the first.
In this example, the common data points shared by the two datastreams are the dimensions ga:deviceCategory and ga:sourceMedium. The join enrichment combines the data based on these shared keys in the data extract.
Joining data from two Google Analytics datastreams
The example in this guide joins data from the two datastreams called Google Analytics Test 1 and Google Analytics Test 2. For more information on how to create these datastreams, see Adding Google Analytics datastreams above.
To join data of two Google Analytics datastreams, follow these steps:
-
Select the workspace you work with in Adverity and then, in the , click Datastreams.
-
In the Enrichments field, click + Create new.
-
Click Custom Script.
-
In Select instruction, write join and press Enter.
-
In the Keys field, click
twice and enter the following field names:
-
ga:deviceCategory
-
ga:sourceMedium
-
-
In the Streams field, click
and enter Google Analytics Test 2.
-
In the Columns field, click
three times and enter the following field names:
-
ga:users
-
ga:transactions
-
ga:totalEvents
Leave the other fields on their default selections.
-
-
Click Next.
-
(Optional) In Enrichment Name, enter a name for the enrichment.
-
Click Create +.
As a result, you have created an enrichment using the Join custom script that will join data from two datastreams. To apply the enrichment, run a data fetch on the datastream to which the enrichment is applied (in this example, run the Join enrichment on the Google Analytics Test 1 datastream).
The join enrichment you have created is a left join enrichment, which means all the data in the datastream to which the enrichment is applied (Google Analytics Test 1) is kept, and any non-matching columns in the data extract of the joining datastream (Google Analytics Test 2) are removed.