import BaseTracker from './BaseTracker'

function loadFacebookPixel () {
  !function(f,b,e,v,n,t,s)
  {if(f.fbq)return;n=f.fbq=function(){n.callMethod?
    n.callMethod.apply(n,arguments):n.queue.push(arguments)};
    if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
    n.queue=[];t=b.createElement(e);t.async=!0;
    t.src=v;s=b.getElementsByTagName(e)[0];
    s.parentNode.insertBefore(t,s)}(window, document,'script',
    'https://connect.facebook.net/en_US/fbevents.js');

  fbq('init', '514962702046652');
  fbq('track', 'PageView')
}

export default class FacebookPixelTracker extends BaseTracker {
  constructor (store) {
    super()

    this.store = store
  }

  async _initializeTracker () {
    this.watchForDisableAllTrackingChanges(this.store)

    if (!this.disableAllTracking) {
      loadFacebookPixel()
    }

    this.onInitializeSuccess()
  }

  // Facebook JS automatically tracks pageviews using history API.  Their docs recommend letting
  // them manage the pageview tracking.
  async trackPageView (includeIntegrations = []) {}

  async trackEvent (action, properties = {}, includeIntegrations = []) {
    if (this.disableAllTracking) {
      return
    }

    await this.initializationComplete

    if (!includeIntegrations.includes('facebook')) {
      return
    }

    fbq('trackCustom', action, properties)
  }
}

@@ -769,65 +769,476 @@
     
-if (!this.disableAllTracking) %7B%0A      loadFacebookPixel()
+// Facebook pixels are currently tracked via Segment, which is enabled for all teachers so do not%0A    // double enable it for teachers%0A    const isTeacher = this.store.getters%5B'me/isTeacher'%5D%0A%0A    const isStudent = this.store.getters%5B'me/isStudent'%5D%0A    const isChina = (window.features %7C%7C %7B%7D).china%0A%0A    if (!this.disableAllTracking && !isTeacher && !isStudent && !isChina) %7B%0A      loadFacebookPixel()%0A      this.enabled = true%0A    %7D else %7B%0A      this.enabled = false
 %0A   
@@ -1642,16 +1642,33 @@
     if (
+!this.enabled %7C%7C 
 !include

disable facebook tracking for students teachers and in china