In App consent implementation via. Google Tag Manager

Amalie Updated by Amalie

In-app measurement with Google Tag Manager

If your Android and iOS application have Google Tag Manager? Then you can implement measurement via. GTM as an alternative to installing the UserReport SDK. 

From a technical perspective, this solution requires a tracking URL to be fired every time a user navigates to a new screen. The set up is the same for both iOS and Android applications.

The tracking URL will look like this:

https://visitanalytics.userreport.com/hit.gif?t={{Tracking Code}}&d={{Advertiser ID}}&med={{App ID}}&os={{Platform}}&osv={{OS Version}}&dn={{Device Name}}&dr={{Screen Resolution}}&iab_consent=BOv_CmhOv_CmhAAABBENDAiAAAAYqABAMUA

Where

  • {{Tracking Code}} - Unique tracking code for application or section - you find the relevant ones using the guide here.
  • {{Advertiser ID}} - Device-wide ID for advertisers IDFA/AAID/OAID depending on platform
  • {{App ID}} - Application ID
  • {{Platform}} - Operation system name (iOS, Android etc)
  • {{OS Version}} - Operation system version
  • {{Device Name}} - Device name, for instance iPad, SM-G973x etc
  • {{Screen Resolution}} - Screen resolution in WIDTHxHEIGHT format

The above tracking URL will need to be fired on every Screen View. 

If your App has sections? Section tracking can be added by using an additional unique tracking code per section, and an additional request in order to track on section level.

1. Preparing Google Tag Manager variables

In order to implement our measurement solution through Google Tag Manager, you will need to make sure that all variables needed are configured on your account. 

  1. On your account, review the list of enabled Variables and make sure the following variables are configured:
    • Advertiser ID
    • Advertiser Tracking Enabled
    • App ID
    • Device Name
    • OS Version
    • Platform
    • Random Number
    • Screen Resolution

  1. Use the Configure button to activate variables if any are missing.
  2. Create a new User-defined variable. Name it “AudienceProject app tcode” and select variable type: Constant. AudienceProject will provide you with a value for each App.
  3. Navigate to Tags and create a new Custom Image Tag. Paste in the URL below, and do not yet set up any triggers.

https://visitanalytics.userreport.com/hit.gif?t={{AudienceProject app tcode}}&d={{Advertiser ID}}&med={{App ID}}&os={{Platform}}&osv={{OS Version}}&dn={{Device Name}}&dr={{Screen Resolution}}&iab_consent=BOv_CmhOv_CmhAAABBENDAiAAAAYqABAMUA

2. Setting up app measurement

Per default, your Google Tag Manager container will have built-in Triggers that will only send tracking events on “Session start” events. This allows you to collect and report on the number of users, but it does not allow you to measure usage level and therefore is not suited for section tracking, as GTM does not ‘know’ when a new piece of content is loaded.Many applications will however send custom events that signal a user’s journey through the application, which can then be used to measure section level events.The following will include installation guides for both scenarios with and without custom events. Please keep in mind that custom events are needed, if you want to measure sections. If your media has no sections? You can use Session Start events as described in 2.2 below.

2.1. With custom events

Let’s assume that there is an already defined Screen-view custom event that the application code fires when a user navigates the application. In this case, you can use this event as a trigger for your tag as shown in the example below.

2.2. Without custom events

If your application has no custom events, update your “AudienceProject app tracking” tag to use Session Start as a trigger.

3. Setting up section measurement

In order to measure sections, your setup will have to meet two criteria:

  1. You must have a Custom event for Screen-view analogue as described in 2.1
  2. You must have the information about to what section a new screen view belongs, available in the data layer or in the event parameters. 

If these conditions are met, then you can setup Section measurement using the following steps:

  1. Make sure there is a Variable that stores the Content category. As an example this can be retrieved from the Event Parameter
  2. You will need to create a Lookup Table with the name “AudienceProject section tcode” variable that will map your Content category to AudienceProject tracking codes provided in Appendix.

  3. Create a new Trigger that will fire when a new Screen View happens AND when “AudienceProject section tcode” as defined in step 2, was looked up. Below an example of trigger configuration:

  4. Create a new Custom Image Tag with URL:

https://visitanalytics.userreport.com/hit.gif?t={{AudienceProject section tcode}}&d={{Advertiser ID}}&med={{App ID}}&os={{Platform}}&osv={{OS Version}}&dn={{Device Name}}&dr={{Screen Resolution}}

- and set trigger “AudienceProject section view” as was defined in step 3.

If your app runs custom consent management requiring explicit opt-in to our measurement services, you need to adjust the URL used within measurement tags in order to direct non-consented requests to a special URL and pipeline. There are two adjustments to be made:

  1. Measurement request needs to land the visitanalytics.dnt-userreport.com
  2. Don’t share a device identifier

To make these two adjustments, it is required to introduce two additional GTM variables:

  • AudienceProject measurement domain - should have value visitanalytics.userreport.com for users consented to measurements and visitanalytics.dnt-userreport.com for the user that have not consented to measurement
  • Consented Advertiser ID - should return value of Advertiser ID only if the user has consented to measurement

You need to follow the steps described below to achieve “anonymous” or non-PID measurement.

It is important to stress that the method only can be applied to a minority of traffic, not 100%. Since consented traffic/events still is necessary in order to deliver proper measurement.

First, you need to communicate the user's consent to measurement to Google Tag Manager, so this knowledge can be used in other tags and variables. There are multiple ways for achieving this based on how the consent is actually implemented. One of the options is to put a key to Firebase User Property with name consented_to_measurement, where value “1” means - user opted in for measurement and “0” - opted out from measurement.

If the consent is already exposed through another variable, you can use the existing one.The two outcomes are needed for you to proceed:

  1. Name of the GTM variable that stores user’s consent
  2. What value constitute consent to measurement

In this documentation the variable has the name “User Consented To Measurement” and the value “1” means that consent was given. These values may be different in your setup.

4.2. Setup AudienceProject measurement domain variable

Now you need to create a variable that will hold the domain for measurement based on the consent. The logic of the variable is simple:

  • if a user consented to measurement, the value should be visitanalytics.userreport.com
  • If a user has not consented to measurement, the value should be visitanalytics.dnt-userreport.com

Name: AudienceProject Measurement Domain

Variable Type: Lookup table

Input Variable: User Consented To Measurement

Lookup table:

Input

Output

0

visitanalytics.dnt-userreport.com

1

visitanalytics.userreport.com

Set Default Value: visitanalytics.dnt-userreport.com

4.3. Setup AudienceProject Advertiser ID variable

Now you need to create a variable that will hold the Advertiser ID, in case the user explicitly consented to measurement.  The logic of the variable is simple:

  • If a user consented to measurement, the value should be taken from Advertiser ID built-in variable
  • If a user has not consented to measurement, the value should remain empty

Name: AudienceProject Advertiser Id

Variable Type: Lookup table

Input Variable: User Consented To Measurement

Lookup table:

Input

Output

1

{{Advertiser ID}}

4.4. Change URLs in measurement tags

Once you set up these variables you need to change URLs in screen and section measurement tags explained in sections 2 and 3.

Screen tracking URL:

https://{{AudienceProject Measurement Domain}}/hit.gif?t={{AudienceProject app tcode}}&d={{AudienceProject Advertiser ID}}&med={{App ID}}&os={{Platform}}&osv={{OS Version}}&dn={{Device Name}}&dr={{Screen Resolution}}

Section tracking URL:

https://{{AudienceProject Measurement Domain}}/hit.gif?t={{AudienceProject section tcode}}&d={{AudienceProject Advertiser ID}}&med={{App ID}}&os={{Platform}}&osv={{OS Version}}&dn={{Device Name}}&dr={{Screen Resolution}}

How did we do?

Android App implementation / Media & Sections

Native App implementation / How to manage consent implementation

Contact