import logger from 'js/utils/logger'

const DEBUG = false

var fbq = window.fbq
if (!fbq) {
  logger.error('Facebook analytics are not available on `window.fbq`.')
}

const facebookAnalytics = (...args) => {
  try {
    if (DEBUG) {
      console.log('Logging Facebook event with args:', args)
    }
    fbq.apply(this, args)
  } catch (e) {
    logger.error(e)
  }
}

export default facebookAnalytics

@@ -31,16 +31,59 @@
 ogger'%0A%0A
+const facebookAnalytics = (...args) =%3E %7B%0A  
 const DE
@@ -99,11 +99,15 @@
 se%0A%0A
-var
+  const
  fbq
@@ -120,16 +120,18 @@
 dow.fbq%0A
+  
 if (!fbq
@@ -134,16 +134,18 @@
 !fbq) %7B%0A
+  
   logger
@@ -212,51 +212,11 @@
 .')%0A
-%7D%0A%0Aconst facebookAnalytics = (...args) =%3E %7B
+  %7D
 %0A  t

Move fbq initialization into function to avoid unnecessary error logs