# Google Analytics 4 Destination Config Reference

<p><a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/google-analytics-4/setup-guide/" >Google Analytics 4</a> is a web and app analytics destination. RudderStack sends events to GA4&rsquo;s Measurement Protocol from its servers, loads Google&rsquo;s own SDKs in device mode, or — for web — splits the two in hybrid mode.</p>
<p>In a Google Analytics 4 destination spec:</p>
<ul>
<li><code>type: ga4</code></li>
<li><code>definition_version: 1</code></li>
</ul>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="sample-configuration">Sample configuration</h2><div class="rs-code">
  <div class="rs-code__head">yaml<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-yaml" data-lang="yaml">version: rudder/v1
kind: destination
metadata:
  name: ga4-prod
spec:
  id: ga4-prod
  display_name: Google Analytics 4 Production
  type: ga4
  definition_version: 1
  enabled: true
  config:
    api_secret: &#34;{{ .GA4_API_SECRET }}&#34;
    client_type: gtag
    measurement_id: &#34;{{ .GA4_MEASUREMENT_ID }}&#34;

    debug_mode: false
    pii_properties_to_ignore:
      - pii_property: email
      - pii_property: phone

    capture_page_view:
      web: rs
    debug_view:
      web: false
    extend_page_view_params:
      web: true
    override_client_and_session_ids:
      web: true

    connection_mode:
      web: hybrid
      cloud: cloud
    consent_management:
      web:
        - provider: oneTrust
          consents:
            - analytics</code></pre></div>
</div>
<p>The above example uses the gtag client with web sources in <code>hybrid</code> mode, which is where <code>override_client_and_session_ids</code> applies — see <a href="#web-sdk-settings" >Web SDK settings</a>.</p>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="config-keys">Config keys</h2><p><code>config</code> accepts only the keys listed below. The <a href="https://www.rudderstack.com/docs/dev-tools/rudder-cli/destination-types/#config-key-rules" >shared config key rules</a> cover unknown keys, defaults, and immutability.</p>

<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text">In <code>cloud</code> mode GA4 accepts <code>track</code>, <code>group</code>, and <code>page</code> events. In <code>device</code> mode, web sources send <code>identify</code>, <code>track</code>, <code>page</code>, and <code>group</code>, and Android and iOS sources send <code>identify</code>, <code>track</code>, and <code>screen</code>. In <code>hybrid</code> mode, <code>page</code> goes through device mode and everything else through cloud mode.</div>
  </div>
</blockquote>

</html>
<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="connection">Connection</h3><div class="rs-ckeys">
<div class="rs-ckey" id="api_secret">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">api_secret</p>RequiredSecret</div>
  <p class="rs-ckey__field">
    Type:
    <code>string</code>
  </p>
<p class="rs-ckey__field">
  Description:
  Measurement Protocol API secret of your GA4 data stream, from <strong>Admin</strong> &gt; <strong>Data Streams</strong> &gt; your stream &gt; <strong>Measurement Protocol API secrets</strong>.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li>At most 100 characters, and must not contain line breaks.</li>
<li>A <code>{{ path || fallback }}</code> template is accepted in place of a literal.</li>
</ul>

</div>

<div class="rs-ckey__extra">
  See <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/google-analytics-4/setup-guide/#how-do-i-obtain-the-api-secret" >How do I obtain the API Secret?</a>.
</div>

</div>

<div class="rs-ckey" id="client_type">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">client_type</p>Required</div>
  <p class="rs-ckey__field">
    Type:
    <code>string</code>
  </p>
<p class="rs-ckey__field">
  Description:
  Which Google client the data stream uses — gtag for websites, Firebase for apps.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li><code>gtag</code> — needs <code>measurement_id</code>. Required for <code>hybrid</code> mode.</li>
<li><code>firebase</code> — needs <code>firebase_app_id</code>.</li>
<li>Templates aren&rsquo;t accepted.</li>
<li>The dashboard defaults this field to <code>gtag</code>. Rudder CLI requires it explicitly.</li>
<li>A spec that omits this key fails validation.</li>
</ul>

</div>

</div>

<div class="rs-ckey" id="measurement_id">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">measurement_id</p>RequiredSecret</div>
  <p class="rs-ckey__field">
    Type:
    <code>string</code>
  </p>
<p class="rs-ckey__field">
  Description:
  Measurement ID of your GA4 web data stream, from <strong>Admin</strong> &gt; <strong>Data Streams</strong> &gt; your stream.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li>Required when <code>client_type</code> is <code>gtag</code>. Leave it unset otherwise.</li>
<li>Must start with <code>G-</code>, followed by 1 to 100 characters.</li>
<li>A <code>{{ path || fallback }}</code> template is accepted in place of a literal.</li>
</ul>

</div>

<div class="rs-ckey__extra">
  See <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/google-analytics-4/setup-guide/#how-do-i-obtain-the-measurement-id" >How do I obtain the Measurement Id?</a>.
</div>

</div>

<div class="rs-ckey" id="firebase_app_id">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">firebase_app_id</p>Required</div>
  <p class="rs-ckey__field">
    Type:
    <code>string</code>
  </p>
<p class="rs-ckey__field">
  Description:
  Firebase App ID of your GA4 app data stream.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li>Required when <code>client_type</code> is <code>firebase</code>. Leave it unset otherwise.</li>
<li>At most 100 characters, and must not contain line breaks.</li>
<li>A <code>{{ path || fallback }}</code> template is accepted in place of a literal.</li>
</ul>

</div>

<div class="rs-ckey__extra">
  See <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/google-analytics-4/setup-guide/#how-do-i-obtain-the-firebase-app-id" >How do I obtain the Firebase App ID?</a>.
</div>

</div>

</div>

<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="event-handling">Event handling</h3><div class="rs-ckeys">
<div class="rs-ckey" id="debug_mode">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">debug_mode</p></div>
  <p class="rs-ckey__field">
    Type:
    <code>boolean</code>
  </p><p class="rs-ckey__field">
    Default value:
    <code>false</code>
  </p>
<p class="rs-ckey__field">
  Description:
  Send cloud-mode events to GA4&rsquo;s validation server instead of reporting them, so you can check validation responses in Live Events. Events sent this way don&rsquo;t appear in reports.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li>Applies to events sent in <code>cloud</code> mode, including the cloud half of <code>hybrid</code> mode.</li>
</ul>

</div>

</div>

<div class="rs-ckey" id="pii_properties_to_ignore">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">pii_properties_to_ignore</p></div>
  <p class="rs-ckey__field">
    Type:
    <code>array of objects</code>
  </p>
<p class="rs-ckey__field">
  Description:
  User traits RudderStack drops before sending events to GA4 — for example email addresses and phone numbers.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li><code>pii_property</code> — the trait name. At most 100 characters, or a <code>{{ path || fallback }}</code> template.</li>
</ul>

</div>

<div class="rs-ckey__extra">
  <div class="rs-code">
  <div class="rs-code__head">yaml<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-yaml" data-lang="yaml">pii_properties_to_ignore:
  - pii_property: email</code></pre></div>
</div>
<p>See <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/google-analytics-4/setup-guide/#how-can-i-prevent-rudderstack-from-sending-pii-fields-to-google-analytics-4" >How can I prevent RudderStack from sending PII fields to Google Analytics 4?</a>.</p>

</div>

</div>

</div>

<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="web-sdk-settings">Web SDK settings</h3><p>These keys configure gtag in the browser, so they apply only when <code>connection_mode.web</code> is <code>device</code> or <code>hybrid</code>. The four objects are keyed by <code>web</code>.</p>
<div class="rs-ckeys">
<div class="rs-ckey" id="sdk_base_url">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">sdk_base_url</p></div>
  <p class="rs-ckey__field">
    Type:
    <code>string</code>
  </p>
<p class="rs-ckey__field">
  Description:
  Custom domain that serves gtag, loaded as <code>https://&lt;domain&gt;/gtag/js</code>. When omitted, <code>https://www.googletagmanager.com</code> is used.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li>Applies when <code>connection_mode.web</code> is <code>device</code> or <code>hybrid</code>.</li>
<li>Must be a domain URL, and any value containing <code>.ngrok.io</code> is rejected. Rudder CLI checks the format only when <code>client_type</code> is <code>gtag</code> and <code>connection_mode.web</code> is <code>device</code>.</li>
<li>A <code>{{ path || fallback }}</code> template is accepted in place of a literal.</li>
</ul>

</div>

</div>

<div class="rs-ckey" id="server_container_url">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">server_container_url</p></div>
  <p class="rs-ckey__field">
    Type:
    <code>string</code>
  </p>
<p class="rs-ckey__field">
  Description:
  URL of your GA4 server-side Google Tag Manager container.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li>Applies when <code>connection_mode.web</code> is <code>device</code> or <code>hybrid</code>.</li>
<li>Not validated locally.</li>
</ul>

</div>

</div>

<div class="rs-ckey" id="capture_page_view">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">capture_page_view</p></div>
  <p class="rs-ckey__field">
    Type:
    <code>object</code>
  </p>
<p class="rs-ckey__field">
  Description:
  How page views reach GA4.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li><code>web</code> — <code>rs</code> (default) to send them from RudderStack&rsquo;s <code>page</code> calls, or <code>gtag</code> to use GA4 Enhanced Measurement&rsquo;s automatic collection on each page load.</li>
<li>Make sure your GA4 measurement configuration matches this setting.</li>
</ul>

</div>

</div>

<div class="rs-ckey" id="debug_view">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">debug_view</p></div>
  <p class="rs-ckey__field">
    Type:
    <code>object</code>
  </p>
<p class="rs-ckey__field">
  Description:
  Show device-mode events in GA4&rsquo;s <a href="https://support.google.com/analytics/answer/7201382" >DebugView</a>. In <code>hybrid</code> mode that covers the <code>page</code> calls only.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li><code>web</code> — boolean. The dashboard defaults it to <code>true</code>; Rudder CLI doesn&rsquo;t fill it in.</li>
</ul>

</div>

</div>

<div class="rs-ckey" id="extend_page_view_params">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">extend_page_view_params</p></div>
  <p class="rs-ckey__field">
    Type:
    <code>object</code>
  </p>
<p class="rs-ckey__field">
  Description:
  Add <code>url</code> and <code>search</code> to the properties sent with each page view. GA4 limits unique properties per event name, so weigh this against your other properties.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li><code>web</code> — boolean.</li>
</ul>

</div>

</div>

<div class="rs-ckey" id="override_client_and_session_ids">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">override_client_and_session_ids</p></div>
  <p class="rs-ckey__field">
    Type:
    <code>object</code>
  </p>
<p class="rs-ckey__field">
  Description:
  Replace gtag&rsquo;s <code>client_id</code> and <code>session_id</code> with RudderStack&rsquo;s <code>anonymousId</code> and <code>session_id</code>, so <code>page</code> calls from the browser and other calls from the server stitch into the same sessions.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li>Applies when <code>connection_mode.web</code> is <code>hybrid</code>. Leave it unset otherwise.</li>
<li><code>web</code> — boolean.</li>
</ul>

</div>

<div class="rs-ckey__extra">
  <blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text">Switching an existing device-mode setup to <code>hybrid</code> with this on can briefly spike session counts. See <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/google-analytics-4/setup-guide/#connection-mode-comparison" >Connection mode comparison</a> for the alternative.</div>
  </div>
</blockquote>

</div>

</div>

</div>

<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="event-filtering">Event filtering</h3>
<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text"><a href="https://www.rudderstack.com/docs/sources/event-streams/sdks/event-filtering/" >Client-side event filtering</a> applies only to sources connected in <code>device</code> mode — web, Android, or iOS. The dashboard shows these controls only then, and the SDK is what applies the filter. Rudder CLI accepts the block in any mode, but it has no effect on cloud-mode connections.</div>
  </div>
</blockquote>
<div class="rs-ckeys">
<div class="rs-ckey" id="event_filtering">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">event_filtering</p></div>
  <p class="rs-ckey__field">
    Type:
    <code>object</code>
  </p>
<p class="rs-ckey__field">
  Description:
  Restricts which <code>track</code> events the SDK passes to GA4, by event name.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li><code>whitelist</code> — array of event names to allow; every other <code>track</code> event is dropped.</li>
<li><code>blacklist</code> — array of event names to drop; every other <code>track</code> event is allowed.</li>
<li>The two are mutually exclusive, and Rudder CLI enforces it — setting both fails validation.</li>
<li>Each name is at most 100 characters, or a <code>{{ path || fallback }}</code> template.</li>
</ul>

</div>

</div>

</div>

<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="per-source-keys">Per-source keys</h3><p>Both keys are objects keyed by the local source type — the tokens listed under <a href="#source-types" >Source types</a>. A key naming a source type this destination doesn&rsquo;t support fails validation.</p>
<div class="rs-ckeys">
<div class="rs-ckey" id="connection_mode">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">connection_mode</p></div>
  <p class="rs-ckey__field">
    Type:
    <code>object</code>
  </p>
<p class="rs-ckey__field">
  Description:
  Maps each source type you connect to the mode its events reach GA4 in, using the modes in <a href="#source-types" >Source types</a>.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li>An entry is required for each source type you connect — see <a href="#connect-a-source" >Connect a source</a>.</li>
<li>A mode the source type doesn&rsquo;t support on this destination fails validation — for example <code>hybrid</code> for <code>android</code>.</li>
</ul>

</div>

<div class="rs-ckey__extra">
  <div class="rs-code">
  <div class="rs-code__head">yaml<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-yaml" data-lang="yaml">connection_mode:
  web: hybrid
  android: device
  cloud: cloud</code></pre></div>
</div>

</div>

</div>

<div class="rs-ckey" id="consent_management">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">consent_management</p></div>
  <p class="rs-ckey__field">
    Type:
    <code>object</code>
  </p>
<p class="rs-ckey__field">
  Description:
  Consent provider configuration per source type. The entry shape, accepted providers, and the rules on <code>resolution_strategy</code> and <code>consents</code> are shared across all destination types — see <a href="https://www.rudderstack.com/docs/dev-tools/rudder-cli/destination-types/#consent-management" >Consent management</a>.
</p>

</div>

</div>

<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="source-types">Source types</h2><p>Google Analytics 4 accepts events from these source types in the mentioned connection modes:</p>
<table>
<thead>
<tr>
<th>Source type</th>
<th>Connection mode</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>android</code></td>
<td><code>cloud</code>, <code>device</code></td>
</tr>
<tr>
<td><code>android_kotlin</code></td>
<td><code>cloud</code></td>
</tr>
<tr>
<td><code>ios</code></td>
<td><code>cloud</code>, <code>device</code></td>
</tr>
<tr>
<td><code>ios_swift</code></td>
<td><code>cloud</code></td>
</tr>
<tr>
<td><code>web</code></td>
<td><code>cloud</code>, <code>device</code>, <code>hybrid</code></td>
</tr>
<tr>
<td><code>unity</code></td>
<td><code>cloud</code></td>
</tr>
<tr>
<td><code>react_native</code></td>
<td><code>cloud</code></td>
</tr>
<tr>
<td><code>flutter</code></td>
<td><code>cloud</code></td>
</tr>
<tr>
<td><code>cordova</code></td>
<td><code>cloud</code></td>
</tr>
<tr>
<td><code>cloud</code></td>
<td><code>cloud</code></td>
</tr>
</tbody>
</table>
<p><code>web</code>, <code>android</code>, and <code>ios</code> offer <code>device</code> mode, and <code>web</code> alone offers <code>hybrid</code>, which needs <code>client_type: gtag</code>. See <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/google-analytics-4/setup-guide/#connection-mode-comparison" >Connection mode comparison</a> and <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/google-analytics-4/hybrid-mode/" >Google Analytics 4 Hybrid Mode</a>.</p>

<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text">The dashboard additionally offers Google Analytics 4 to AMP, Shopify, and Reverse ETL sources. Rudder CLI doesn&rsquo;t manage those connections, so <code>amp</code>, <code>shopify</code>, and <code>warehouse</code> are invalid here.</div>
  </div>
</blockquote>

</html>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="connect-a-source">Connect a source</h2><p>An event stream connection to this destination is checked against two rules at <code>validate</code> time.</p>
<p><strong>The source&rsquo;s type must be supported.</strong> A source&rsquo;s type resolves to one of the tokens above before the check — a JavaScript source resolves to <code>web</code>, and webhook and server-side SDK sources resolve to <code>cloud</code>. An unsupported type reports:</p>
<div class="rs-code">
  <div class="rs-code__head"><button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-text" data-lang="text">destination &#39;ga4-prod&#39; (type &#39;ga4&#39;) does not support source &#39;my-source&#39;:
source type &#39;amp&#39; is not among supported source types: android, android_kotlin, ...</code></pre></div>
</div>
<p><strong>The destination config must carry a <code>connection_mode</code> entry for that source type.</strong> This lives on the destination spec, not on the <a href="https://www.rudderstack.com/docs/dev-tools/rudder-cli/yaml-connections/" >connection spec</a>. Without it:</p>
<div class="rs-code">
  <div class="rs-code__head"><button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-text" data-lang="text">destination &#39;ga4-prod&#39; config has no &#39;connection_mode&#39; entry for source type &#39;web&#39;</code></pre></div>
</div>
<p>Google Analytics 4 needs no additional config keys to connect a source of any type, in any mode.</p>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="secrets">Secrets</h2><p><code>api_secret</code> and <code>measurement_id</code> are the secret keys. Write each as a <code>{{ .VAR }}</code> reference and supply the value at apply time:</p>
<div class="rs-code">
  <div class="rs-code__head">yaml<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-yaml" data-lang="yaml">config:
  api_secret: &#34;{{ .GA4_API_SECRET }}&#34;
  measurement_id: &#34;{{ .GA4_MEASUREMENT_ID }}&#34;</code></pre></div>
</div>
<div class="rs-code">
  <div class="rs-code__head">bash<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-bash" data-lang="bash">export RUDDER_GA4_API_SECRET=&#34;...&#34;
export RUDDER_GA4_MEASUREMENT_ID=&#34;G-XXXXXXXXXX&#34;
rudder-cli apply

# or
rudder-cli apply --var-file secrets.vars.yaml</code></pre></div>
</div>
<p>Note that:</p>
<ul>
<li>The YAML that <code>rudder-cli import</code> writes may or may not include secret keys. Before you apply, make sure every secret key your configuration needs is present and populated through variable substitution.</li>
<li>In device and hybrid mode the measurement ID is embedded in the page&rsquo;s JavaScript, so masking it protects your YAML, not the value itself.</li>
<li><code>firebase_app_id</code> isn&rsquo;t a secret and is imported as-is.</li>
</ul>
<p>See <a href="https://www.rudderstack.com/docs/dev-tools/rudder-cli/variable-substitution/" >How to Use Variable Substitution in Rudder CLI</a>.</p>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="see-more">See more</h2><ul>
<li><a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/google-analytics-4/setup-guide/" >Google Analytics 4 Destination</a> for obtaining the IDs and choosing a connection mode</li>
<li><a href="https://www.rudderstack.com/docs/dev-tools/rudder-cli/destination-types/" >Destination Type Reference for Rudder CLI</a> for the rules shared across destination types</li>
<li><a href="https://www.rudderstack.com/docs/dev-tools/rudder-cli/yaml-destinations/" >Destination YAML Reference</a> for the spec envelope</li>
</ul>

