Need to capture gads phone calls in GHL CRM pls help me with proper code

61 views
Skip to first unread message

Deepak Kari

unread,
Aug 7, 2024, 11:45:24 AM8/7/24
to Google Ads Scripts Forum
function main() {
  // Define the date range for retrieving call data
  var startDate = getFormattedDate(30); // 30 days ago
  var endDate = getFormattedDate(0); // today

  // Construct the query string with proper date formatting
  var query = 'SELECT CallStartTime, CampaignName, CallerCountryCode, CallDurationSeconds, CallStatus ' +
              'FROM CALL_METRICS_CALL_DETAILS_REPORT ' +
              'WHERE CallStartTime >= "' + startDate + '" AND CallStartTime <= "' + endDate + '"';

  // Query to get call details
  var report = AdsApp.report(query);

  var rows = report.rows();

  // Check if there are any rows to process
  if (!rows.hasNext()) {
    Logger.log('No call data found for the specified date range.');
    return;
  }

  while (rows.hasNext()) {
    var row = rows.next();
    var callData = {
      startTime: row['CallStartTime'],
      campaign: row['CampaignName'],
      countryCode: row['CallerCountryCode'],
      duration: row['CallDurationSeconds'],
      status: row['CallStatus']
    };

    // Send data to the webhook URL
    sendToWebhook(callData);
  }
}

function sendToWebhook(data) {
  var url = 'https://services.leadconnectorhq.com/hooks/GWgJnGNYokMRdIAB4fm2/webhook-trigger/9ea53395-eb21-4cb4-9752-1c59033b44ca'; // Replace with your GoHighLevel webhook URL
  var options = {
    method: 'POST',
    contentType: 'application/json',
    payload: JSON.stringify(data)
  };

  try {
    var response = UrlFetchApp.fetch(url, options);
    Logger.log('Data sent to webhook: ' + response.getContentText());
  } catch (e) {
    Logger.log('Error sending data to webhook: ' + e.toString());
  }
}

function getFormattedDate(daysAgo) {
  var date = new Date();
  date.setDate(date.getDate() - daysAgo);
  var year = date.getFullYear();
  var month = ('0' + (date.getMonth() + 1)).slice(-2);
  var day = ('0' + date.getDate()).slice(-2);
  return year + '-' + month + '-' + day + 'T00:00:00'; // Format as 'YYYY-MM-DDTHH:MM:SS'
}

Confidentiality Notice: This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure, or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. Thank you for respecting the privacy and security of the information contained in this email. Digital Presence Matters™.

Google Ads Scripts Forum Advisor

unread,
Aug 7, 2024, 2:08:53 PM8/7/24
to adwords...@googlegroups.com

Hi,

Thank you for reaching out to the Google Ads Scripts support team.

Could you please provide more information on the issue you are facing ? If possible, share with us the following details to investigate the issue further :

  • Google Ads account ID or CID
  • Name of the affected script in the account
  • Error details or screenshot of the issue
You can send the details via Reply privately to the author option, or direct private reply to this email.
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02vEf7k:ref" (ADR-00262366)

Thanks,
 
Google Logo Google Ads Scripts Team


Deepak Kari

unread,
Aug 13, 2024, 7:00:48 AM8/13/24
to Google Ads Scripts Forum
Google Ads integrated with Go High Level CRM to capture the leads,
forms leads i can able to track in the CRM
Phone call leads am not able to track in the CRM 
Planned to Integrate Via Webhook to capture phone call leads through google ads.
took script from chat GPT and troubled shouted, but still am facing with this error.


07/08/2024 20:22:18

Ga: 'CallerCountryCode' is not a valid field in CALL_METRICS_CALL_DETAILS_REPORT. Please check your spelling and casing. 
at main (Code:12:23) 

Reply all
Reply to author
Forward
0 new messages