Get More Local Leads with Google Local Services Ads — Plans Start at $600/Month
0 like 0 dislike
418 views
by Marketing Guru (7.4k points)

1 Answer

0 like 0 dislike
by Marketing Guru (8.0k points)

Google’s readAnalyticsStorage API lets you retrieve GA4’s client ID and session ID inside Google Tag Manager,  but only if the user has granted analytics_storage consent. This removes the need for cookie parsing and makes your tracking privacy-compliant.

Here’s exactly how to use it in practice:

1. Enable Consent Mode in GTM

  • Go to Admin > Consent Settings in GTM.

  • Enable Consent Mode.

  • Set up triggers that fire only when analytics_storage is granted.

2. Create a Custom Template in GTM

  • In GTM, go to Templates > New > Tag Template.

  • Add the API call:

[javascript]

const ids = await readAnalyticsStorage();

if (ids) {

  const clientId = ids.clientId;

  const sessionId = ids.sessionId;

  // Send to your desired platform

}

  • Save and publish the template.

3. Capture IDs When Consent Is Given

  • Create a new Tag using your custom template.

  • Set the trigger to fire when:

    • Form submissions occur, OR

    • A specific event is tracked (e.g., purchase, lead).

  • Make sure your trigger checks for analytics_storage consent.

4. Send IDs to Your Destination

Example: Sending to a CRM

  • Add a hidden field in your lead form for the GA client ID.

  • When the form is submitted, GTM passes the ID into that hidden field and sends it along with the form data.

Example: Sending to Google Ads for Enhanced Conversions

  • Use the Enhanced Conversions tag in GTM.

  • Pass the GA client ID as an additional parameter for better matching.

5. Test Your Setup

  • Use GTM Preview Mode to ensure the tag only fires when consent is granted.

  • Check your GA4 DebugView or your CRM logs to confirm IDs are being sent correctly.

Result: You’ll have reliable, consent-compliant GA4 IDs for attribution and tracking, without breaking privacy laws or relying on fragile JavaScript hacks.

Join a specialized Q&A site for digital marketing experts focused on ad platforms like Google, Facebook, YouTube, LinkedIn, Bing, Quora, and more. Connect with peers to share strategies on client retention beyond acquisition. Discuss and solve technical, managerial, or general challenges to improve your ad campaigns and client relationships.

Register to unlock your digital marketing potential!
Get More Local Leads!
Google Local Services Ads
Starting at $600/Month

Most popular tags

google-ads facebook-ads meta-ads amazon-fba amazon-ads amazon-seller-help youtube-ads ad-campaigns x-ads amazon-2026 pinterest-ads performance-max paid-advertising glsa amazon-storefront ppc-strategy amazon-ppc amazon-seller-account twitter-ads local-service-ads server-side-tracking tiktok-ads conversion-tracking ppc-marketing google-analytics google-tag-manager server-side-tagging ppc ga4 dv-360 google-business-profile campaign-optimization facebook-pixel white-label-agency dynamic-keyword-insertion tools-to-find-keywords microsoft-advertisement feature-snippet-types meta-threads white-label-advertising convertion-tracking feature-snippet performance-marketing-agency pinterest-conversion-lift-study amazon-ungatedwholesale advantage-plus keyword-research shopify bing-ads-ppc video-ads ad-performance amazon-listing marchupdate2026 ppc-optimization metabusinessmanager landing-page mcc-google youtube-trueview-ads google-ads-calls-from-website-conversion pitch-digital-marketing-services pitch-deck-creation tiktok2026 sales-tax-exemptions audience-targeting ad-optimization ppc-landing-page learning-phase creative-testing google-merchant-listings google-local-service-ads disclosure-rule amazon-fbm ahrefs-keyword-difficulty display-ads demand-gen-campaigns dropshipping clickable-ads gtm amazon-product-listing budget-management creative-optimization looker-studio-report trend-genius-ai pinterest-carousel-ads bing-ads-management ppc-campaigns meta-carousel-ads pmax-campaigns campaign-structure microsoft-ads ad-creatives lead-generation landing-page-optimization advantage-campaigns microsoft-advertising-editor search-ads phased-campaign-strategy digital-marketing-tips digital-advertising negative-keywords
...