{"version":3,"file":"index.mjs","sources":["../src/index.ts","../src/utils.ts"],"sourcesContent":["import { injectScript } from \"./utils\";\n\nconst TryDatacops = {\n  init(apiKey: string, serverUrl?: string) {\n    injectScript(apiKey, serverUrl);\n  },\n  eventSetup(type: string, data: any) {\n    if (!window.tdcScope) {\n      window.tdcScope = [];\n    }\n    window.tdcScope.push(\n      window.tdcScope.push({\n        type,\n        data,\n      })\n    );\n  },\n};\n\nexport default TryDatacops;\n","export function injectScript(apiKey: string, serverUrl?: string): void {\n  serverUrl = serverUrl?.replace(/^https?:\\/\\//, \"\");\n  try {\n    (function (\n      t: Window /* window */,\n      r: Document /* document */,\n      y: string /* tdcScope */,\n      da: string /* script */,\n      ta: string /* apiKey */,\n      co?: HTMLScriptElement,\n      ps?: HTMLElement\n    ) {\n      if (r.getElementById(\"tdc_script\")) {\n        return;\n      }\n\n      // Create a global function `tdcScope` that queues calls\n      (t as any)[y] =\n        (t as any)[y] ||\n        function () {\n          ((t as any)[y].q = (t as any)[y].q || []).push(arguments);\n        };\n\n      // Create a new script element\n      co = r.createElement(da) as HTMLScriptElement;\n      co.async = true;\n      co.src = `https://cdn.trydatacops.com/?kick_key=${ta}`;\n      co.id = \"tdc_script\";\n\n      // Find the first existing script tag\n      ps = r.getElementsByTagName(da)[0] as HTMLElement;\n      ps.parentNode?.insertBefore(co, ps);\n    })(window, document, \"tdcScope\", \"script\", apiKey);\n    return;\n  } catch (error) {\n    console.error(\"Error injecting script:\", error);\n    return;\n  }\n}\n"],"names":["TryDatacops","init","apiKey","serverUrl","replace","t","window","r","document","y","da","ta","getElementById","q","push","arguments","co","createElement","async","src","concat","id","_a","ps","getElementsByTagName","parentNode","insertBefore","error","console","injectScript","eventSetup","type","data","tdcScope"],"mappings":"AAEA,IAAMA,EAAc,CAClBC,KAAI,SAACC,EAAgBC,ICHP,SAAaD,EAAgBC,GAC3CA,EAAYA,aAAA,EAAAA,EAAWC,QAAQ,eAAgB,IAC/C,IA+BE,OA7BEC,EA4BCC,OA3BDC,EA2BSC,SA1BTC,EA0BmB,WAzBnBC,EAyB+B,SAxB/BC,EAwByCT,OApBrCK,EAAEK,eAAe,gBAKpBP,EAAUI,GACRJ,EAAUI,IACX,YACIJ,EAAUI,GAAGI,EAAKR,EAAUI,GAAGI,GAAK,IAAIC,KAAKC,UAChD,GAGHC,EAAKT,EAAEU,cAAcP,IAClBQ,OAAQ,EACXF,EAAGG,IAAM,yCAAyCC,OAAAT,GAClDK,EAAGK,GAAK,aAIO,QAAfC,GADAC,EAAKhB,EAAEiB,qBAAqBd,GAAI,IAC7Be,kBAAY,IAAAH,GAAAA,EAAAI,aAAaV,EAAIO,KAGlC,MAAOI,GAEP,YADAC,QAAQD,MAAM,0BAA2BA,GAhCzC,IACEtB,EACAE,EACAE,EACAC,EACAC,EACAK,EACAO,GA4BN,CDlCIM,CAAa3B,EAAQC,EACtB,EACD2B,WAAU,SAACC,EAAcC,GAClB1B,OAAO2B,WACV3B,OAAO2B,SAAW,IAEpB3B,OAAO2B,SAASnB,KACdR,OAAO2B,SAASnB,KAAK,CACnBiB,KAAIA,EACJC,KAAIA,IAGT"}