{"version":3,"sources":["../src/types/index.ts","../src/index.ts"],"sourcesContent":["import type { Mapping, WalkerOS } from '@elbwalker/types';\nimport type { DestinationWeb } from '@elbwalker/walker.js';\n\ndeclare global {\n  interface Window {\n    plausible?: Plausible & { q?: IArguments[] };\n  }\n}\n\nexport type Plausible = (\n  event: string,\n  options?: { props?: WalkerOS.AnyObject },\n) => void;\n\nexport interface Destination\n  extends DestinationWeb.Destination<Custom, CustomEvent> {}\n\nexport type Config = DestinationWeb.Config<Custom, CustomEvent>;\n\nexport interface Custom {\n  domain?: string; // Name of the domain to be tracked\n}\n\nexport type EventConfig = Mapping.EventConfig<CustomEvent>;\n\nexport interface CustomEvent {}\n","import type { Config, Destination } from './types';\nimport { isObject } from '@elbwalker/utils';\n\n// Types\nexport * as DestinationPlausible from './types';\n\nexport const destinationPlausible: Destination = {\n  type: 'plausible',\n\n  config: {},\n\n  init(config = {}) {\n    const w = window;\n    const custom = config.custom || {};\n\n    if (config.loadScript) addScript(custom.domain);\n\n    w.plausible =\n      w.plausible ||\n      function () {\n        (w.plausible!.q = w.plausible!.q || []).push(arguments);\n      };\n  },\n\n  push(event, config, mapping, options = {}) {\n    const { fn } = config;\n    const params = isObject(options.data) ? options.data : {};\n\n    const func = fn || window.plausible!;\n    func(`${event.event}`, params);\n  },\n};\n\nfunction addScript(\n  domain?: string,\n  src = 'https://plausible.io/js/script.manual.js',\n) {\n  const script = document.createElement('script');\n  script.src = src;\n  if (domain) script.dataset.domain = domain;\n  document.head.appendChild(script);\n}\n\nexport default destinationPlausible;\n"],"mappings":";;;;;;;;;AAAA;;;ACMO,IAAM,uBAAoC;AAAA,EAC/C,MAAM;AAAA,EAEN,QAAQ,CAAC;AAAA,EAET,KAAK,SAAS,CAAC,GAAG;AAChB,UAAM,IAAI;AACV,UAAM,SAAS,OAAO,UAAU,CAAC;AAEjC,QAAI,OAAO,WAAY,WAAU,OAAO,MAAM;AAE9C,MAAE,YACA,EAAE,aACF,WAAY;AACV,OAAC,EAAE,UAAW,IAAI,EAAE,UAAW,KAAK,CAAC,GAAG,KAAK,SAAS;AAAA,IACxD;AAAA,EACJ;AAAA,EAEA,KAAK,OAAO,QAAQ,SAAS,UAAU,CAAC,GAAG;AACzC,UAAM,EAAE,GAAG,IAAI;AACf,UAAM,SAAS,EAAS,QAAQ,IAAI,IAAI,QAAQ,OAAO,CAAC;AAExD,UAAM,OAAO,MAAM,OAAO;AAC1B,SAAK,GAAG,MAAM,KAAK,IAAI,MAAM;AAAA,EAC/B;AACF;AAEA,SAAS,UACP,QACA,MAAM,4CACN;AACA,QAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,SAAO,MAAM;AACb,MAAI,OAAQ,QAAO,QAAQ,SAAS;AACpC,WAAS,KAAK,YAAY,MAAM;AAClC;AAEA,IAAO,gBAAQ;","names":[]}