import { Analytics } from '../../../core/analytics' import { logger } from '../../logger' import { IIntentSourcesSourceOptions } from '../types' interface ISnitcherData { company: { domain: string employee_range: string industry: string name: string revenue: { amount: string } } type: string } declare global { interface Window { SpotterSettings?: { callback: (data: ISnitcherData) => Promise token: string } } } export function loadSnitcher( analytics: Analytics, options: IIntentSourcesSourceOptions ): void { if (!options.token) { logger.error( 'Token is missing for the Snitcher intent source. Make sure it is included in your script setup.' ) return } async function dreamdataCallback(identification: ISnitcherData) { if ( !identification || identification.type !== 'business' || analytics.group().traits()?.website ) return const reveal = identification.company await analytics.group(null, { website: reveal.domain, intentSource: 'snitcher', name: reveal.name || undefined, industry: reveal.industry || undefined, number_of_employees: reveal.employee_range || undefined, annual_revenue: reveal.revenue.amount || undefined, }) } window.SpotterSettings = { token: options.token, callback: dreamdataCallback, } }