1"use strict";(globalThis.webpackChunkdocusaurus_test=globalThis.webpackChunkdocusaurus_test||[]).push([[37250],{5998(e,n,o){o.r(n),o.d(n,{assets:()=>l,contentTitle:()=>a,default:()=>h,frontMatter:()=>i,metadata:()=>s,toc:()=>c});let s=JSON.parse('{"id":"pmw/developers/recipes/track-phone-conversions-for-multiple-store-locations","title":"Track Phone Conversions for Multiple Store Locations","description":"Track Google Ads phone call conversions for several store locations, each with its own phone number and conversion label, instead of the single number you can configure in the Pixel Manager settings.","source":"@site/docs/pmw/developers/recipes/track-phone-conversions-for-multiple-store-locations.md","sourceDirName":"pmw/developers/recipes","slug":"/pmw/developers/recipes/track-phone-conversions-for-multiple-store-locations","permalink":"/docs/pmw/developers/recipes/track-phone-conversions-for-multiple-store-locations","draft":false,"unlisted":false,"tags":[],"version":"current","lastUpdatedAt":1782394118000,"sidebarPosition":2,"frontMatter":{"sidebar_position":2},"sidebar":"pmwSidebar","previous":{"title":"Status-Driven Purchase Conversions","permalink":"/docs/pmw/developers/recipes/status-driven-purchase-events"},"next":{"title":"Integrate a Third-Party Conversion Tag","permalink":"/docs/pmw/developers/recipes/third-party-conversion-tag"}}');var t=o(74848),r=o(28453);let i={sidebar_position:2},a="Track Phone Conversions for Multiple Store Locations",l={},c=[{value:"When you need this recipe",id:"when-you-need-this-recipe",level:2},{value:"Before you start",id:"before-you-start",level:2},{value:"Recipe",id:"recipe",level:2},{value:"How it works",id:"how-it-works",level:2},{value:"Tracking several numbers on one page",id:"tracking-several-numbers-on-one-page",level:2},{value:"Troubleshooting",id:"troubleshooting",level:2},{value:"Related",id:"related",level:2}];function d(e){let n={a:"a",admonition:"admonition",blockquote:"blockquote",code:"code",h1:"h1",h2:"h2",header:"header",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,r.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.header,{children:(0,t.jsx)(n.h1,{id:"track-phone-conversions-for-multiple-store-locations",children:"Track Phone Conversions for Multiple Store Locations"})}),"\n",(0,t.jsx)(n.p,{children:"Track Google Ads phone call conversions for several store locations, each with its own phone number and conversion label, instead of the single number you can configure in the Pixel Manager settings."}),"\n",(0,t.jsx)(n.h2,{id:"when-you-need-this-recipe",children:"When you need this recipe"}),"\n",(0,t.jsxs)(n.p,{children:["The Pixel Manager's ",(0,t.jsx)(n.strong,{children:"Phone Conversion Number"})," setting holds one number and one conversion label. If you run multiple locations (for example a store with seven branches, each with its own phone number), you need a different number and conversion label per location. This recipe wires that up through the Pixel Manager's ",(0,t.jsx)(n.a,{href:"/docs/pmw/developers/command-queue",children:"Command Queue"})," and consent handling, so each location's number is tracked at the right time and only after consent."]}),"\n",(0,t.jsxs)(n.admonition,{title:"Google tracks one number per page",type:"info",children:[(0,t.jsxs)(n.p,{children:["Google's website call tracking swaps a displayed phone number for a Google forwarding number to attribute calls to ad clicks. With the standard gtag JavaScript, this is limited to a ",(0,t.jsx)(n.strong,{children:"single number per page"}),". Google states it directly:"]}),(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:"Only one number can be tracked on a single page using the default Javascript tag."}),"\n"]}),(0,t.jsxs)(n.p,{children:["Source: ",(0,t.jsx)(n.a,{href:"https://support.google.com/google-ads/answer/6095883",children:"Set up tracking calls to a phone number on a website"})," (Google Ads Help)."]}),(0,t.jsxs)(n.p,{children:["So the supported model is ",(0,t.jsx)(n.strong,{children:"one tracked number per page"}),": give each location its own page and map that page to its number. Showing several numbers on one shared page is covered ",(0,t.jsx)(n.a,{href:"#tracking-several-numbers-on-one-page",children:"further down"}),"."]})]}),"\n",(0,t.jsx)(n.h2,{id:"before-you-start",children:"Before you start"}),"\n",(0,t.jsxs)(n.ol,{children:["\n",(0,t.jsxs)(n.li,{children:["In Google Ads, create one ",(0,t.jsx)(n.strong,{children:'"Calls from a website"'})," conversion action per location. Each gives you a conversion label, so the full conversion target for a location looks like ",(0,t.jsx)(n.code,{children:"AW-123456789/AbCdEf123"}),"."]}),"\n",(0,t.jsx)(n.li,{children:"Give each location its own page that displays that location's phone number."}),"\n",(0,t.jsxs)(n.li,{children:["Leave the ",(0,t.jsx)(n.strong,{children:"Phone Conversion Number"})," and ",(0,t.jsx)(n.strong,{children:"Phone Conversion Label"})," fields in the Pixel Manager settings empty, since this recipe handles all locations."]}),"\n"]}),"\n",(0,t.jsx)(n.h2,{id:"recipe",children:"Recipe"}),"\n",(0,t.jsxs)(n.p,{children:["Add the following to your child theme's ",(0,t.jsx)(n.code,{children:"functions.php"}),". Fill in the ",(0,t.jsx)(n.code,{children:"$locations"})," map (one row per location page) and adjust the ",(0,t.jsx)(n.code,{children:"is_page()"})," matching to your pages."]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-php",metastring:'title="/wp-content/themes/child-theme/functions.php"',children:"add_action( 'wp_head', function () {\n\n // One entry per location page (page => the number shown on it + its conversion target).\n $locations = array(\n 'contact-new-yor
1k' => array( 'number' => '+1 212-555-0100', 'label' => 'AW-123456789/AbCdEf123' ),\n 'contact-boston' => array( 'number' => '+1 617-555-0100', 'label' => 'AW-123456789/GhIjKl456' ),\n 'contact-chicago' => array( 'number' => '+1 312-555-0100', 'label' => 'AW-123456789/MnOpQr789' ),\n // ... add the remaining locations\n );\n\n // Pick the entry for the current page (adapt the matching to your site).\n $entry = null;\n foreach ( $locations as $page => $data ) {\n if ( is_page( $page ) ) {\n $entry = $data;\n break;\n }\n }\n\n if ( null === $entry ) {\n return;\n }\n ?>\n <script>\n window._pmwq = window._pmwq || [];\n window._pmwq.push( function () {\n var phoneNumber = <?php echo wp_json_encode( $entry['number'] ); ?>;\n var conversionLabel = <?php echo wp_json_encode( $entry['label'] ); ?>;\n\n // gtag and consent both arrive asynchronously, so check every 300ms\n // until ready, then fire once. Covers normal load, lazy load and late consent.\n var tries = 0;\n var poll = setInterval( function () {\n if ( ++tries > 200 ) { clearInterval( poll ); return; } // give up after ~60s\n if ( typeof window.gtag !== 'function' ) { return; } // gtag not loaded yet\n if ( ! pmw.googleConfigConditionsMet || ! pmw.googleConfigConditionsMet( { type: 'marketing' } ) ) { return; } // no consent (yet)\n gtag( 'config', conversionLabel, { phone_conversion_number: phoneNumber } );\n clearInterval( poll );\n }, 300 );\n } );\n <\/script>\n <?php\n}, 1 );\n"})}),"\n",(0,t.jsxs)(n.p,{children:["The ",(0,t.jsx)(n.code,{children:"number"})," must match the number ",(0,t.jsx)(n.strong,{children:"exactly as it appears on the page"})," (same digits and format), so Google's dynamic number insertion can find and swap it."]}),"\n",(0,t.jsx)(n.h2,{id:"how-it-works",children:"How it works"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsxs)(n.strong,{children:[(0,t.jsx)(n.a,{href:"/docs/pmw/developers/command-queue",children:"Command Queue"})," (",(0,t.jsx)(n.code,{children:"window._pmwq"}),")"]})," runs the code as soon as the Pixel Manager API is available, no matter how or when the plugin loads (including script deferral and lazy loading)."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.strong,{children:"The poll"})," handles the fact that ",(0,t.jsx)(n.code,{children:"gtag"})," is created asynchronously and that consent may be granted late. It checks every 300ms until both ",(0,t.jsx)(n.code,{children:"window.gtag"})," exists and consent is in place, fires once, then stops (with a safety cap of about 60 seconds)."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.strong,{children:"Consent"})," is gated through the same check the Pixel Manager uses for its own Google Ads conversions (",(0,t.jsx)(n.code,{children:"pmw.googleConfigConditionsMet({ type: 'marketing' })"}),"). When Google Consent Mode is active this returns ",(0,t.jsx)(n.code,{children:"true"})," and gtag handles consent; when it is not, the call fires only after marketing consent. A phone call conversion is a marketing signal, so ",(0,t.jsx)(n.code,{children:"marketing"})," is the correct category."]}),"\n"]}),"\n",(0,t.jsx)(n.h2,{id:"tracking-several-numbers-on-one-page",children:"Tracking several numbers on one page"}),"\n",(0,t.jsx)(n.p,{children:"If you want to show all of your locations' numbers on a single shared page, the standard gtag tag cannot track them. Google's guidance for that case is the advanced manual install or Google Tag Manager:"}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsx)(n.p,{children:"You should use this option if you want to track calls to multiple phone numbers on your website."}),"\n"]}),"\n",(0,t.jsxs)(n.p,{children:["(from the same ",(0,t.jsx)(n.a,{href:"https://support.google.com/google-ads/answer/6095883",children:"Google Ads Help page"}),"). That path is outside the scope of this recipe; the per-page setup above is the recommended approach."]}),"\n",(0,t.jsx)(n.h2,{id:"troubleshooting",children:"Troubleshooting"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.strong,{children:"The number is not being swapped."})," Confirm the ",(0,t.jsx)(n.code,{children:"number"})," matches the digits shown on the page exactly. You can test Google's swapping by appending ",(0,t.jsx)(n.code,{children:"#google-wcc-debug"})," to the page URL."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.strong,{children:"Nothing fires."})," Make sure the page is matched by your ",(0,t.jsx)(n.code,{children:"is_page()"})," logic, and that the Google Ads pixel is active in the Pixel Manager. The snippet only fires after marketing consent is granted."]}),"\n",(0,t.jsxs)(n.li,{children:[(0,t.jsx)(n.strong,{children:"The conversion is attributed to the wrong location."})," Each location needs its own conversion action (its own label) in Google Ads, and its own page."]}),"\n"]}),"\n",(0,t.jsx)(n.h2,{id:"related",children:"Related"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsx)(n.li,{children:(0,t.jsx)(n.a,{href:"/docs/pmw/developers/command-queue",children:"Command Queue"})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsx)(n.a,{href:"/docs/pmw/developers/event-filters",children:"Event Filters"})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsx)(n.a,{href:"/docs/pmw/plugin-configuration/google-ads",children:"Google Ads configuration"})}),"\n"]})]})}function h(e={}){let{wrapper:n}={...(0,r.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(d,{...e})}):d(e)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.