UNPKG

@logsnag/remix

Version:

LogSnag client for Remix applications

1 lines 3.76 kB
{"version":3,"sources":["../src/client/provider.tsx","../../../utilities/constants/src/cdn.ts","../../../utilities/hooks/src/funcs.ts","../../../utilities/hooks/src/hooks.ts"],"sourcesContent":["import React from 'react';\nimport { CDN_URL } from '@logsnag/constants/src/cdn';\n\nexport interface ILogSnagProviderProps {\n project: string;\n token: string;\n}\n\n/**\n * Set up the LogSnag provider\n * @param props: ILogSnagProviderProps\n * @constructor\n */\nexport const LogSnagProvider: React.FC<\n React.PropsWithChildren<ILogSnagProviderProps>\n> = ({ project, token, children }) => {\n // if window is undefined, we're not in a browser\n if (typeof window !== 'undefined') {\n window.lsq = window.lsq || [];\n window.ls = window.ls || ((...args) => window.lsq?.push(args));\n }\n\n React.useEffect(() => {\n // update the config with the project and token\n window.ls('setConfig', token, project);\n\n const script = document.createElement('script');\n script.id = 'logsnag-script';\n script.src = CDN_URL;\n script.async = true;\n\n // prevent multiple initializations\n if (!document.getElementById(script.id)) {\n document.body.appendChild(script);\n }\n return () => {\n document.body.removeChild(script);\n };\n }, [project, token]);\n return <>{children}</>;\n};\n","export const CDN_URL = 'https://cdn.logsnag.com/web/ls.js';\n","import '@logsnag/web/types/gloabl';\nimport { TrackOptions } from '@logsnag/core';\nimport { IdentifyOptions } from '@logsnag/core';\nimport { PartialBy } from '@logsnag/web/types/tracker';\n\n/**\n * Set the user id for the current user\n * if the user is not logged in, pass null\n * @description\n */\nexport const setUserId = (userId: string | null) => {\n window.ls('setUserId', userId);\n};\n\n/**\n * Clear the user id for the current user\n */\nexport const clearUserId = () => {\n window.ls('clearUserId');\n};\n\n/**\n * Set debug mode for logging\n */\nexport const setDebug = (flag: boolean = true) => {\n window.ls('setDebug', flag);\n};\n\n/**\n * Track custom events\n */\nexport const track = (options: TrackOptions) => {\n window.ls('track', options);\n};\n\n/**\n * Identify user traits\n */\nexport const identify = (options: PartialBy<IdentifyOptions, 'user_id'>) => {\n window.ls('identify', options);\n};\n","import { clearUserId, identify, setDebug, setUserId, track } from './funcs';\n\n/**\n * LogSnag Hook\n * @description\n */\nexport const useLogSnag = () => {\n return {\n setDebug,\n setUserId,\n clearUserId,\n track,\n identify\n };\n};\n"],"mappings":";AAAA,OAAOA,MAAW,QCAX,IAAMC,EAAU,oCDahB,IAAMC,EAET,CAAC,CAAE,QAAAC,EAAS,MAAAC,EAAO,SAAAC,CAAS,KAE1B,OAAO,QAAW,cACpB,OAAO,IAAM,OAAO,KAAO,CAAC,EAC5B,OAAO,GAAK,OAAO,KAAO,IAAIC,IAAM,CAnBxC,IAAAC,EAmB2C,OAAAA,EAAA,OAAO,MAAP,YAAAA,EAAY,KAAKD,MAG1DE,EAAM,UAAU,IAAM,CAEpB,OAAO,GAAG,YAAaJ,EAAOD,CAAO,EAErC,IAAMM,EAAS,SAAS,cAAc,QAAQ,EAC9C,OAAAA,EAAO,GAAK,iBACZA,EAAO,IAAMC,EACbD,EAAO,MAAQ,GAGV,SAAS,eAAeA,EAAO,EAAE,GACpC,SAAS,KAAK,YAAYA,CAAM,EAE3B,IAAM,CACX,SAAS,KAAK,YAAYA,CAAM,CAClC,CACF,EAAG,CAACN,EAASC,CAAK,CAAC,EACZI,EAAA,cAAAA,EAAA,cAAGH,CAAS,GE7Bd,IAAMM,EAAaC,GAA0B,CAClD,OAAO,GAAG,YAAaA,CAAM,CAC/B,EAKaC,EAAc,IAAM,CAC/B,OAAO,GAAG,aAAa,CACzB,EAKaC,EAAW,CAACC,EAAgB,KAAS,CAChD,OAAO,GAAG,WAAYA,CAAI,CAC5B,EAKaC,EAASC,GAA0B,CAC9C,OAAO,GAAG,QAASA,CAAO,CAC5B,EAKaC,EAAYD,GAAmD,CAC1E,OAAO,GAAG,WAAYA,CAAO,CAC/B,EClCO,IAAME,EAAa,KACjB,CACL,SAAAC,EACA,UAAAC,EACA,YAAAC,EACA,MAAAC,EACA,SAAAC,CACF","names":["React","CDN_URL","LogSnagProvider","project","token","children","args","_a","React","script","CDN_URL","setUserId","userId","clearUserId","setDebug","flag","track","options","identify","useLogSnag","setDebug","setUserId","clearUserId","track","identify"]}