theme-puretheme-puretheme-puretheme-pure

Google Conversions

HeavySet Tech - Facilitating Lead Acquisition with Modern Tech Solutions

HeavySet Tech & Google Conversions

How to Send a Google Conversion When a New Lead is Created Using HeavySet Tech

Introduction

Google's Enhanced Conversions are an innovative way of providing better accuracy in your conversion measurements. By using first-party data, such as email addresses, it enables Google Ads to match conversions even in scenarios where cookies might not be available or effective. This in turn allows advertisers to have a clearer picture of how their ads are performing and the actual returns they're yielding.

HeavySet Tech, recognizing the significance of this, has incorporated a mechanism to communicate with parent websites using an iframe. When a lead is submitted in HeavySet Tech's iframe component, it sends a message to the parent website. The parent site can then process this data and send it as a Google Conversion. In this article, we'll walk you through how to set this up.

Setting up Google's Global Site Tag

Before you can send conversion events, ensure that your website has the necessary scripts loaded. Add the following script to your site:

<!-- Global site tag (gtag.js) - Google Ads -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-CONVERSION_ID"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'AW-CONVERSION_ID', { allow_enhanced_conversions: true });
</script>

Replace 'AW-CONVERSION_ID' with your actual Google Ads Conversion ID.

Handling the Message from HeavySet Tech's iframe

Now, when a lead is submitted via the HeavySet Tech iframe, a message of type "leadSubmission" is sent to the parent website. The following code sample outlines how to capture this event and then send it to Google as a conversion:

function isGoogleSource() {
    var referrerIsGoogle = document.referrer.indexOf('google.') !== -1;
    var urlParams = new URLSearchParams(window.location.search);
    var hasGclid = urlParams.has('gclid');
    var sourceIsGoogle = urlParams.get('source') && urlParams.get('source').toLowerCase().indexOf('google') !== -1;
    var sourceTypeIsGoogle = urlParams.get('sourceType') && urlParams.get('sourceType').toLowerCase().indexOf('google') !== -1;

    return referrerIsGoogle || hasGclid || sourceIsGoogle || sourceTypeIsGoogle;
}

function sendGoogleLeadConversion(leadData) {
  // You can find the conversion ID and conversion label under Google Ads -> Goals 
  // -> Summary -> Conversion action (select action) -> Tag setup -> Use Google Tag Manager
  var conversionId = 'AW-CONVERSION_ID';
  var conversionLabel = 'CONVERSION_LABEL';

  // Make sure field names match conversion action under Google Ads -> Goals
  // -> Summary -> Conversion action (select action) -> Enhanced conversions
  window.gtag('set', 'user_data', {
    email: leadData.email,
    phone_number: leadData.phoneNumber,
    address: {
      first_name: leadData.firstName,
      last_name: leadData.lastName,
      street: leadData.street,
      postal_code: leadData.postalCode,
      country: leadData.country,
    },
  });

  // Send the conversion event
  window.gtag('event', 'conversion', {
    send_to: conversionId + '/' + conversionLabel, // 'AW-CONVERSION_ID/CONVERSION_LABEL',
    currency: 'USD',
    transaction_id: leadData.oneTimeToken, // unique id for session from HeavySet Tech, prevents duplicates
  });
}

window.addEventListener('message', function (event) {
  if (event.origin !== 'https://apt-ui-classic1.heavyset.tech') return;
  if (event.data.type === 'leadSubmission') {
    var leadData = event.data.data;
    if (isGoogleSource()) {
      sendGoogleLeadConversion(leadData);
    }
  }
}, false);

Ensure to replace 'AW-CONVERSION_ID/CONVERSION_LABEL' with your actual Google Ads Conversion ID and Conversion Label.

Conclusion

Integrating HeavySet Tech's iframe component with Google Enhanced Conversions offers a powerful way to get deeper insights into user interactions and lead generation. By following the steps and code samples outlined above, you can efficiently track conversions and improve your digital marketing strategies.

About Heavy Set Technologies LLC

Founded in 2023, Heavy Set Technologies LLC began with a simple goal: to improve the lead acquisition process for businesses. Using modern technologies and design, we aim to provide flexible and scalable solutions to assist businesses in their lead generation efforts.

Learn more about what we offer and explore our services at heavyset.tech.