|
| 1 | +export const GOOGLE_ADS_ID = "AW-16740819749" |
| 2 | + |
| 3 | +/** Send-to labels for each conversion goal */ |
| 4 | +export const CONVERSION_IDS = { |
| 5 | + beginCheckout: `${GOOGLE_ADS_ID}/qUthCNieibYcEKXG0q4-`, |
| 6 | + subscribe: `${GOOGLE_ADS_ID}/2l-5CNueibYcEKXG0q4-`, |
| 7 | + purchase: `${GOOGLE_ADS_ID}/eDjjCN6eibYcEKXG0q4-`, |
| 8 | + submitLeadForm: `${GOOGLE_ADS_ID}/CY9iCOGeibYcEKXG0q4-`, |
| 9 | + pageView: `${GOOGLE_ADS_ID}/li9bCOSeibYcEKXG0q4-`, |
| 10 | + signUp: `${GOOGLE_ADS_ID}/ElPhCOeeibYcEKXG0q4-`, |
| 11 | + getDirections: `${GOOGLE_ADS_ID}/E4xrCOqeibYcEKXG0q4-`, |
| 12 | + requestQuote: `${GOOGLE_ADS_ID}/WWVMCO2eibYcEKXG0q4-`, |
| 13 | + outboundClick: `${GOOGLE_ADS_ID}/Y6xZCPCeibYcEKXG0q4-`, |
| 14 | + contact: `${GOOGLE_ADS_ID}/Z1z3CJGcoLYcEKXG0q4-`, |
| 15 | +} as const |
| 16 | + |
| 17 | +declare global { |
| 18 | + interface Window { |
| 19 | + gtag: (...args: unknown[]) => void |
| 20 | + dataLayer: unknown[] |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +function fireConversion( |
| 25 | + sendTo: string, |
| 26 | + extra?: Record<string, unknown>, |
| 27 | +): void { |
| 28 | + if (typeof window === "undefined" || typeof window.gtag !== "function") return |
| 29 | + window.gtag("event", "conversion", { send_to: sendTo, ...extra }) |
| 30 | +} |
| 31 | + |
| 32 | +/** Ready-to-call helpers for each conversion goal */ |
| 33 | +export const conversions = { |
| 34 | + beginCheckout: () => fireConversion(CONVERSION_IDS.beginCheckout), |
| 35 | + subscribe: () => fireConversion(CONVERSION_IDS.subscribe), |
| 36 | + /** @param transactionId Optional order / invoice ID */ |
| 37 | + purchase: (transactionId = "") => |
| 38 | + fireConversion(CONVERSION_IDS.purchase, { transaction_id: transactionId }), |
| 39 | + submitLeadForm: () => fireConversion(CONVERSION_IDS.submitLeadForm), |
| 40 | + pageView: () => fireConversion(CONVERSION_IDS.pageView), |
| 41 | + signUp: () => fireConversion(CONVERSION_IDS.signUp), |
| 42 | + getDirections: () => fireConversion(CONVERSION_IDS.getDirections), |
| 43 | + requestQuote: () => fireConversion(CONVERSION_IDS.requestQuote), |
| 44 | + outboundClick: () => fireConversion(CONVERSION_IDS.outboundClick), |
| 45 | + contact: () => fireConversion(CONVERSION_IDS.contact), |
| 46 | +} |
0 commit comments