Google Analytics: Setup Custom Dimensions
Lytics has the ability to pass all public audiences as a Custom Dimension to Google Analytics out-of-the-box. This allows for global filters based on Lytics audiences to be applied to reports, custom views and nearly every aspect of your existing Google Analytics account.
Integration Details
- Implementation Type: Server-side and Client-side.
- Implementation Technique: REST API with JavaScript Tag.
- Frequency: Real-time.
- Resulting data: Audiences in Google Analytics.
This integration uses the Google Anlytics Universal Analytics API and the Google Analytics GA4 APIs.
Custom dimensions
Lytics User ID
andLytics Audiences
will be created if they haven't been already been created with user-level scope.Note: The authorization must have the Google Analytics Editor role to create Custom Dimensions.
Once this job has completed, this will activate the Lytics JS Tag to send Lytics Audience membership along with the Lytics User ID as a collect event to the Google Analytics tag through the two mapped dimensions above, when users visit your web property that has both Lytics and Google Analytics tags installed.
Configuration
If you are new to creating jobs in Lytics, see the Jobs Dashboard documentation for more information.
- Select Google Marketing from the list of providers.
- Select the Google Analytics: Setup Dimensions job type from the list.
- Select the Authorization you would like to use or create a new one.
- Enter a Label to identify this job you are creating in Lytics.
- (Optional) Enter a Description for further context on your job.
- From the Google Analytics Account input, select the Google Analytics account to use. This menu will be populated with all Google Analytics accounts the authorization has access to.
- From the Google Analytics Version input, select whether Google Analytics 4 or Google Universal Analytics is used.
- From the Web Property input, select which Google Analytics web property to use. This will be the web property you use for all future Google Analytics data syncs.
- Select Google Analytics 360 if you have one, which enables you to create up to 200 custom dimensions instead of 20.
- From the Lytics Audiences Custom Dimension input, select which custom dimension you would like to pass Lytics audiences to. We'll create one for you labeled "Lytics Audiences" if nothing is selected (recommended).
- From the Lytics User ID Custom Dimension input, select which custom dimension to pass Lytics user IDs to. One will be created for you labeled "Lytics User ID" if nothing is selected (recommended).
- Using the Export Fields configuration Lytics has the ability to pass additional data into Google Analytics. Lytics Support should be consulted prior to configuring this field in order to ensure your account will allow for it.
- Click Start Export.
Configure Lytics Audiences in GA
The final step is to configure the display of Lytics audiences within your Google Analytics account. For full details on how to leverage custom dimensions across Google Analytics, please consult Google's documentation.
Create Google Analytics Segments from Lytics Data
- From your Audience Overview inside of Google Analytics select Add Segment towards the top.
- Select the red + New Segment button at the top of the list of existing Google segments.
- Name your segment in the following window. This is what will appear in your reporting and across your Google Analytics interface.
- Under Advanced select Conditions. This allows you to create Google Segments from custom dimensions.
- Select the dropdown menu that sets the dimension (often this will default to Ad Content) and from the dropdown menu expand Custom Dimensions and click on the Lytics Audiences dimension.
- In the text input to the right of contains, type in the ID of your audience. This can be found on the Lytics audience overview next to the full audience name. In the example shown below,
mobile_web_visitor
would be used as the audience ID. Note: the audiences you use must be API enabled. - Save your Google segment. You can now activate or deactivate this segment at any time to filter all aspects of your Google Analytics dashboard.
Lytics Event Override
By default, this integration will fire a Google Analytics event on each page load. This ensures all audience data is associated with the visitor and received by Google. If you would like to prevent this additional event on page load, Lytics offers a custom override that prevents Google Analytics from sending the initial "pageview" event until Lytics audiences have been set properly each time a visitor views a page.
- Blocklist the native Google Analytics integration. This is required in order to prevent duplicate events.
- Alter the Google Analytics Website Tracking tag. The default Google Analytics Website Tracking tag automatically triggers a "pageview" after it has been loaded. To prevent the additional Lytics event this event call must be removed. To do so, simply remove the following line from the default Google Analytics Website tracking code:
ga('send', 'pageview');
Install the following Lytics Google Analytics integration snippet. This code should be located just below your Google Analytics Website Tracking code.
<script> !function(l,a){a.liosetup=a.liosetup||{},a.liosetup.callback=a.liosetup.callback||[],a.liosetup.addEntityLoadedCallback=function(l){if("function"==typeof a.liosetup.callback){var o=[];o.push(a.liosetup.callback),a.liosetup.callback=o}a.lio&&a.lio.loaded?l(a.lio.data):a.liosetup.callback.push(l)}}(document,window); !function(e,n){var i=function(e){ga(function(){for(var e=ga.getAll(),i=[],a=0,t=e.length;a<t;a++){var o=e[a].get("trackingId"),g=e[a].get("name");o&&i.push({name:g,id:o})}for(a=0;a<n.lio.integrationsConfig.googleAdsIntegration.length;a++)for(var l=n.lio.integrationsConfig.googleAdsIntegration[a],d=0;d<i.length;d++)if(l.web_property===i[d].id){var g=i[d].name;n.ga(g+".require","displayfeatures"),n.ga(g+".set",l.segments_dimension,n.lio.segmentsString),n.ga(g+".set",l.user_id_dimension,n.lio._uid),ga("send","pageview")}})};n.liosetup&&"function"==typeof n.liosetup.addEntityLoadedCallback?n.liosetup.addEntityLoadedCallback(i):console.warn("unable to add Lytics callback, missing callback handler")}(document,window); </script>
Here is a full example denoting the proper load order:
<html> <head> <!-- Google Analytics Website Tracking --> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-35220005-2', 'auto'); // ga('send', 'pageview'); <--- this is the line you will comment out or remove </script> <!-- Lytics Google Analytics Integration --> <script> !function(l,a){a.liosetup=a.liosetup||{},a.liosetup.callback=a.liosetup.callback||[],a.liosetup.addEntityLoadedCallback=function(l){if("function"==typeof a.liosetup.callback){var o=[];o.push(a.liosetup.callback),a.liosetup.callback=o}a.lio&&a.lio.loaded?l(a.lio.data):a.liosetup.callback.push(l)}}(document,window); !function(e,n){var i=function(e){ga(function(){for(var e=ga.getAll(),i=[],a=0,t=e.length;a<t;a++){var o=e[a].get("trackingId"),g=e[a].get("name");o&&i.push({name:g,id:o})}for(a=0;a<n.lio.integrationsConfig.googleAdsIntegration.length;a++)for(var l=n.lio.integrationsConfig.googleAdsIntegration[a],d=0;d<i.length;d++)if(l.web_property===i[d].id){var g=i[d].name;n.ga(g+".require","displayfeatures"),n.ga(g+".set",l.segments_dimension,n.lio.segmentsString),n.ga(g+".set",l.user_id_dimension,n.lio._uid),ga("send","pageview")}})};n.liosetup&&"function"==typeof n.liosetup.addEntityLoadedCallback?n.liosetup.addEntityLoadedCallback(i):console.warn("unable to add Lytics callback, missing callback handler")}(document,window); </script> </head> <body> </body> </html>
Lytics Event Override with Google Tag Manager
For those who are using Google Tag Manager, the steps are slightly different due to how load order and integrations are handled within that tool.
Configure Google Analytics Tag
- Select Tags from the menu and click New to create a new tag container.
- Click Choose a tag type to begin setup... and select Custom HTML from the list.
- Within this container you will place your Google Analytics tracking tag as instructed in step 2 of the Lytics Event Override section above. Essentially, you will copy and paste the Google Analytics tracking code and then remove the
ga('send', 'pageview');
line so that Lytics does not send the pageview data before all data has been set with Google. - Under the Advanced Settings, adjust the Tag Firing Priority to be
10
for this tag. The higher the number, the sooner the script runs. - Click on Triggering to configure when the tag is triggered. This is likely going to be All Pages but is dependent on execution details.
- Name your tag and click Save.
Configure Lytics Tag
- Select Tags from the menu and click New to create a new tag container.
- Click Choose a tag type to begin setup... and select Custom HTML from the list.
- In this tag you will paste the "Lytics Google Analytics Integration" from step 3 of the Lytics Event Override section above.
- Under the Advanced Settings, adjust the Tag Firing Priority to be
9
for this tag. This ensures Lytics will run after Google Analytics has been initialized. - Click on Triggering to configure when the tag is triggered. This is likely going to be All Pages but is dependent on execution details. This must match the targeting used in the Google Analytics container otherwise your GA tag will not fire.
- Name your tag and click Save.
At this point, everything should be configured. Publishing the latest version of your tag manager should result in audiences being passed into your Google Analytics account without sending additional, unnecessary events.
Verifying the Integration
A simple way to test that everything is working properly is to use the Google Analytics Debugger Chrome extension from Google. When activated, all of the data that is being passed to Google will also be output in your Google Developer Console. You will simply need to look for the Lytics audiences list in your event as seen here: