Integration Guide

Instagram Ads → Quantum + Admin

End-to-end flow: create Instagram lead ads, capture leads automatically, and route them into your Quantum CRM & Admin Dashboard.

Overview

Architecture at a Glance

📸 Instagram Lead Ad Meta Lead Center / Graph API Webhook (Meta → Cloud Function) Cloud Function (processInstagramLead) Firestore: inquiries / instagramLeads Admin Dashboard + Quantum CRM

Instagram Lead Form Ads capture user info (name, email, phone) without leaving Instagram. Meta sends this data to your webhook → Cloud Function writes to Firestore → Admin & Quantum show it instantly.

Phase 1

Meta Business Suite Setup

Before creating ads, ensure your Meta Business infrastructure is ready:

📌 Already Done: Your Meta Pixel is live on 69dynamics.in. Facebook Page + Ads Manager should already be connected.
Phase 2

Create the Instagram Lead Ad

Step-by-step in Meta Ads Manager:

Step 1: Campaign

  • Go to Ads Manager → + Create
  • Objective: Leads
  • Campaign name: e.g., IG_LeadGen_Mar2026
  • Enable Campaign Budget Optimization (CBO) if desired

Step 2: Ad Set

  • Lead method: Instant Forms (lead form inside Instagram — no redirect)
  • Audience: Target by location (Tamil Nadu / India / your target), age 25–55, interests: "Small business", "Digital marketing", "Entrepreneurship", "E-commerce"
  • Placements: Manual → Instagram Feed + Instagram Stories + Instagram Reels
  • Budget: Start with ₹500–₹1,000/day
  • Schedule: Run for 7 days initially, then optimize

Step 3: Ad Creative

  • Use the ad image from /images/ad-creatives/instagram-lead-ad.html — open in browser, screenshot at 1080×1080
  • Primary text: "Your business deserves a digital edge. Websites, marketing, CRM & branding — all under one roof. Get a free quote today."
  • Headline: "Free Consultation — Limited Slots"
  • CTA Button: "Get Quote" or "Learn More"

Step 4: Instant Form Setup

  • Form type: More Volume (easier for users) or Higher Intent (adds review step)
  • Intro: Short headline + 1-line value prop
  • Questions: Name (prefilled), Email (prefilled), Phone Number, "What service are you interested in?" (dropdown: Website, Digital Marketing, Branding, Quantum CRM, App Development, Other)
  • Privacy Policy link: https://69dynamics.in/privacy
  • Thank You screen: "Thanks! We'll contact you within 24 hours." + Link to website
💡 Pro Tip: Use "Higher Intent" form type if your budget is limited — fewer but more qualified leads. Use "More Volume" if you want maximum reach.
Phase 3

Webhook: Meta → Cloud Function

To receive leads automatically (instead of manually downloading CSVs), set up a webhook:

Step 1: Create the Cloud Function

Add this to functions/index.js:

// ── Instagram Lead Webhook ── exports.instagramLeadWebhook = functions.https.onRequest(async (req, res) => { // Webhook verification (GET request from Meta) if (req.method === 'GET') { const mode = req.query['hub.mode']; const token = req.query['hub.verify_token']; const challenge = req.query['hub.challenge']; if (mode === 'subscribe' && token === process.env.META_VERIFY_TOKEN) { return res.status(200).send(challenge); } return res.status(403).send('Forbidden'); } // Lead data (POST request from Meta) if (req.method === 'POST') { const body = req.body; if (body.object === 'page') { for (const entry of body.entry) { for (const change of entry.changes) { if (change.field === 'leadgen') { const leadgenId = change.value.leadgen_id; const pageId = change.value.page_id; // Fetch full lead data from Graph API const leadData = await fetchLeadFromGraph(leadgenId); // Write to Firestore await admin.firestore().collection('instagramLeads').add({ leadgenId, pageId, formId: change.value.form_id, ...leadData, source: 'instagram_lead_ad', status: 'new', createdAt: admin.firestore.FieldValue.serverTimestamp() }); // Also create an inquiry for Admin Dashboard await admin.firestore().collection('inquiries').add({ name: leadData.name || '', email: leadData.email || '', phone: leadData.phone || '', service: leadData.service || 'General', message: `[Instagram Lead Ad] ${leadData.service || 'Inquiry'}`, source: 'instagram', status: 'new', createdAt: admin.firestore.FieldValue.serverTimestamp() }); } } } } return res.status(200).send('OK'); } res.status(405).send('Method not allowed'); }); // Helper: fetch lead details from Meta Graph API async function fetchLeadFromGraph(leadgenId) { const fetch = (await import('node-fetch')).default; const accessToken = process.env.META_PAGE_ACCESS_TOKEN; const url = `https://graph.facebook.com/v19.0/${leadgenId}?access_token=${accessToken}`; const resp = await fetch(url); const data = await resp.json(); // Parse field_data array into a flat object const fields = {}; if (data.field_data) { for (const f of data.field_data) { fields[f.name] = f.values?.[0] || ''; } } return { name: fields.full_name || fields.first_name || '', email: fields.email || '', phone: fields.phone_number || '', service: fields.what_service_are_you_interested_in || '', rawFields: fields }; }

Step 2: Set Environment Variables

# Set these in Firebase Functions config firebase functions:config:set meta.verify_token="YOUR_RANDOM_VERIFY_TOKEN" firebase functions:config:set meta.page_access_token="YOUR_PAGE_ACCESS_TOKEN" # Or use .env file in functions/ directory META_VERIFY_TOKEN=your_random_secret_string META_PAGE_ACCESS_TOKEN=your_long_lived_page_access_token

Step 3: Get the Page Access Token

  • Go to developers.facebook.com → Your App → Tools → Graph API Explorer
  • Select your Page → Permissions: pages_manage_ads, leads_retrieval, pages_show_list, pages_read_engagement
  • Generate a long-lived Page Access Token (valid 60 days → extend to never-expire via API)

Step 4: Register Webhook in Meta

  • Go to developers.facebook.com → Your App → Webhooks
  • Subscribe to Page → object: leadgen
  • Callback URL: https://asia-south1-dynamics-69.cloudfunctions.net/instagramLeadWebhook
  • Verify Token: same value you set in META_VERIFY_TOKEN
  • Click Verify and Save
  • Then subscribe your Page to this webhook
🔒 Security: Always validate the verify token. In production, also verify the X-Hub-Signature-256 header using your App Secret to prevent spoofed webhook calls.
Phase 4

Admin Dashboard Integration

Once the webhook writes to the inquiries collection, leads appear automatically in Admin:

Optional: Dedicated Instagram Leads Section

To add a separate view in Admin, add a filter/tab that queries:

// Filter inquiries by Instagram source db.collection('inquiries') .where('source', '==', 'instagram') .orderBy('createdAt', 'desc') .onSnapshot(snapshot => { // Render Instagram leads in a dedicated tab });

Or query the instagramLeads collection for richer data (includes form ID, leadgen ID, raw fields).

Phase 5

Quantum CRM Integration

For client-facing Quantum dashboards, Instagram leads flow through the same pipeline:

Auto-Create Client Profile (Optional)

// Inside the webhook function, after creating inquiry: await admin.firestore().collection('clientProfiles').add({ name: leadData.name, email: leadData.email, phone: leadData.phone, source: 'instagram_lead_ad', status: 'lead', interestedIn: leadData.service, createdAt: admin.firestore.FieldValue.serverTimestamp() });

This creates a lead profile in Quantum instantly — no manual data entry needed.

Phase 6

Deploy & Test

⏱ Timeline: Meta webhook verification is instant. First real leads should flow within minutes of the ad going live. Leads are written to Firestore in real-time.
Phase 7

Monitor & Optimize

Key Metrics to Watch

  • CPL (Cost Per Lead): Target ₹50–₹200 for India
  • Form Completion Rate: Should be > 30%
  • Lead → Response Time: Contact within 1 hour for best conversion
  • Lead → Client Conversion: Track in Admin/Quantum