<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">define(['app'], function(app) {
  var analyticsHelper = function($location) {
    var affilationName = 'Pro Page'
    var productPrefix = {
      track: 'track-',
      soundKit: 'soundKit-',
      album: 'album-',
      service: 'service-',
      negotiation: 'negotiation-',
      merch: 'merch-',
      merchVariant: 'merch-variant-',
    }
    var service = {
      // Methods
      sendPageView: sendPageView,
      sendTrackEvents: sendTrackEvents,
      sendCartEvents: sendCartEvents,
      sendV3CartEvents: sendV3CartEvents,
      sendEcommerceEvent: sendEcommerceEvent,

      // Enhanced Ecommerce Tracking Methods
      viewItemList: viewItemList,
      viewItem: viewItem,

      // Custom Pro Page Events
      sendSearchEvent: sendSearchEvent,
      sendDownloadEvent: sendDownloadEvent,
    }

    return service

    function sendPageView() {
      googleEventSender('page_view', { send_to: gaIds, page_location: $location.path() })
    }

    function sendTrackEvents(action, track) {
      googleEventSender(action, {
        send_to: gaIds,
        id: productPrefix.track + track.v2Id,
        name: track.title,
        event_category: 'engagement',
        event_label: track.title,
      })

      facebookEventSender('trackCustom', action, {
        content_name: track.title,
        content_ids: productPrefix.track + track.v2Id,
        content_type: 'product_group',
      })
    }

    function viewItemList(itemType, listName, list) {
      var sendData = {
        items: [],
        send_to: gaIds,
        event_label: 'Viewed ' + listName + ': ' + itemType.toUpperCase(),
      }
      var contentIds = []
      for (var i = 0; i &lt; list.length; i++) {
        sendData.items.push({
          id: getItemId(itemType, list[i]),
          name: getItemName(itemType, list[i]),
          list_name: listName,
          brand: getItemBrand(itemType, list[i]),
          category: itemType,
          list_position: i + 1,
        })

        contentIds.push(getItemId(itemType, list[i]))
      }

      googleEventSender('view_item_list', sendData)

      if (canSendEventForProductType(itemType)) {
        facebookEventSender('track', 'ViewContent', {
          content_ids: contentIds,
          content_type: 'product_group',
        })
      }
    }

    function canSendEventForProductType(itemType) {
      return itemType === 'track' || itemType === 'album' || itemType === 'soundKit'
    }

    function viewItem(itemType, itemData, productClick) {
      var productId = getItemId(itemType, itemData)
      try {
        var sendData = {
          items: [
            {
              id: productId,
              name: getItemName(itemType, itemData),
              brand: getItemBrand(itemType, itemData),
              category: itemType,
            },
          ],
          send_to: gaIds,
          event_label: 'Viewed ' + itemType.toUpperCase() + ': ' + getItemName(itemType, itemData),
        }

        if (productClick) {
          googleEventSender('select_content', sendData)
        } else {
          googleEventSender('view_item', sendData)
        }
      } catch (e) {}

      facebookEventSender('track', 'ViewContent', {
        content_ids: productId,
        content_type: 'product_group',
        content_name: getItemName(itemType, itemData)
      })

      tiktokEventSender('ViewContent', {
        content_id: productId,
        content_type: 'product',
        content_name: getItemName(itemType, itemData),
        currency: 'USD',
        value: !!itemData.price ? itemData.price : 0,
      })
    }

    function getItemId(itemType, itemData) {
      switch (itemType) {
        case 'track':
          return productPrefix[itemType] + (itemData.v2Id || itemData.track_id || itemData.details.v2Id)
        case 'album':
          return productPrefix[itemType] + (itemData.v2Id || itemData.album_id || itemData.details.v2Id)
        case 'soundKit':
        case 'soundkit':
          return productPrefix[itemType] + (itemData.v2Id || itemData.soundkit_id || itemData.details.v2Id)
        case 'service':
        case 'legacy_service':
          return productPrefix[itemType] + (itemData.v2Id || itemData.service_id || itemData.details.v2Id)
        case 'merch':
        case 'legacy_merchandise':
          return productPrefix[itemType] + itemData.id || itemData.details.v2Id
        case 'merchVariant':
          return productPrefix[itemType] + itemData.merchandise_variant_id || itemData.details.v2Id
      }
    }

    function getItemName(itemType, itemData) {
      if (itemType === 'merch' || itemType === 'merchandise') {
        return itemData.name
      } else {
        return itemData.title || itemData.details.title
      }
    }

    function getItemBrand(itemType, itemData) {
      if (itemType === 'merch' || itemType === 'merchandise') {
        return itemData.musician.display_name
      } else {
        return itemData.profile.displayName || itemData.details.musician.display_name
      }
    }

    function sendCartEvents(action, productType, properties, cartData) {
      if (typeof properties !== 'object') {
        return
      }

      try {
        var contentId = getItemId(productType, properties)
        var itemsData = []
        try {
          itemsData = [
            {
              id: contentId,
              name: properties.title,
              variant:
                properties.product_type === 'merchandise'
                  ? properties.object.details.color
                  : properties.license_name.replace(/(&lt;([^&gt;]+)&gt;)/gi, ''),
              quantity: properties.quantity,
              price: properties.discounted_amount || properties.salePrice,
            },
          ]
        } catch (e) { console.error(e) }

        googleEventSender(action, {
          send_to: gaIds,
          id: contentId,
          event_category: 'ecommerce',
          event_label: action !== 'removed_from_cart' ? cartData.added : cartData.removed,
          items: itemsData,
        })

        facebookEventSender('track', action, {
          content_id: contentId,
          content_type: 'product',
          value: cartData.added_amt,
          currency: 'USD',
        })

        if (action === 'add_to_cart') {
          tiktokEventSender('AddToCart', {
            content_type: 'product',
            quantity: properties.quantity,
            content_id: contentId,
            currency: 'USD',
            value: cartData.added_amt,
          })
        }
      } catch (e) {}
    }

    function sendV3CartEvents(action, productType, properties) {
      if (typeof properties !== 'object') {
        return
      }

      try {
        var contentId = getItemId(productType, properties)
        var itemsData = []
        try {
          itemsData = [
            {
              id: contentId,
              name: properties.details.title,
              variant:
                productType === 'legacy_merchandise'
                  ? properties.details.color
                  : properties.details.subTitle,
              quantity: properties.quantity,
              price: properties.salePrice,
            },
          ]
        } catch (e) { console.error(e) }

        googleEventSender(action, {
          send_to: gaIds,
          id: contentId,
          event_category: 'ecommerce',
          event_label: productType + ':' + properties.details.title,
          items: itemsData,
        })

        facebookEventSender('track', action, {
          content_id: contentId,
          content_type: 'product',
          value: properties.salePrice,
          currency: 'USD',
        })

        if (action === 'add_to_cart') {
          tiktokEventSender('AddToCart', {
            content_type: 'product',
            quantity: properties.quantity,
            content_id: contentId,
            currency: 'USD',
            value: properties.salePrice,
          })
        }
      } catch (e) {
        console.log(e)
      }
    }

    function sendEcommerceEvent(transactionData) {
      var contentIds = []

      try {
        var orderItems = new Array()
        for (var itemIndex = 0; itemIndex &lt; transactionData.items.length; itemIndex++) {
          var item = transactionData.items[itemIndex]
          var contentId = ''
          switch (item.product.type) {
            case 'TRACK':
              contentId = productPrefix['track'] + item.product.id
              if (item.product.license_id &amp;&amp; item.product.license_id != 0) {
                contentId = contentId + '-' + item.product.license_id
              }
              break
            case 'ALBUM':
              contentId = productPrefix['album'] + item.product.id
              if (item.product.license_id &amp;&amp; item.product.license_id != 0) {
                contentId = contentId + '-' + item.product.license_id
              }
              break
            case 'SOUND_KIT':
              contentId = productPrefix['soundKit'] + item.product.id
              break
            case 'SERVICE_INVOICE':
              contentId = productPrefix['service'] + item.product.id
              break
            case 'SERVICE':
              contentId = productPrefix['service'] + item.product.id
              break
            case 'MERCHANDISE':
              contentId = productPrefix['merchVariant'] + item.product.id
              break
            case 'NEGOTIATION_DEAL':
              contentId = productPrefix['negotiation'] + item.product.id
              break
          }

          orderItems.push({
            id: contentId,
            name: item.product.title,
            brand: item.product.musician.display_name,
            category: item.product.type,
            variant: item.product.description ? item.product.description : '',
            quantity: item.quantity,
            price: item.sale_price,
          })

          contentIds.push(contentId)
        }

        googleEventSender('purchase', {
          transaction_id: transactionData.invoice_number,
          affiliation: affilationName + ':Cart',
          value: transactionData.total_amount,
          currency: 'USD',
          shipping: transactionData.shipping_amount,
          tax: 0,
          items: orderItems,
          send_to: gaIds,
        })
      } catch (gaError) {}

      try {
        facebookEventSender('track', 'Purchase', {
          currency: 'USD',
          value: transactionData.total_amount,
          content_type: 'product',
          content_ids: contentIds,
          invoice_number: transactionData.invoice_number,
          num_items: transactionData.items.length,
        })
      } catch (fbError) {}

      try {
        tiktokEventSender('CompletePayment', {
          currency: 'USD',
          value: transactionData.total_amount,
          content_type: 'product',
          contents: contentIds,
          invoice_number: transactionData.invoice_number,
          quantity: transactionData.items.length,
        })
      } catch (tiktokError) {}
    }

    function sendSearchEvent(query) {
      try {
        googleEventSender('search', {
          search_term: query,
        })
      } catch (gaError) {}

      try {
        facebookEventSender('track', 'Search', {
          search_string: query,
        })
      } catch (fbError) {}

      try {
        tiktokEventSender('Search', {
          content_id: 'pro_page_search',
          query: query,
        })
      } catch (tiktokError) {}
    }

    function sendDownloadEvent() {
      // This will be used in the future
      try {
        tiktokEventSender('Download', {})
      } catch (tiktokError) {}
    }

    // Google Analytics
    function googleEventSender() {
      if (arguments.length &lt;= 0) {
        return
      }

      try {
        switch (arguments.length) {
          case 3:
            gtag('event', arguments[0], arguments[1], arguments[2])
            break
          case 2:
            gtag('event', arguments[0], arguments[1])
            break
          case 1:
            gtag('event', arguments[0])
            break
        }
      } catch (e) {}
    }

    // Facebook Pixel Methods
    function facebookEventSender() {
      if (arguments.length &lt;= 0) {
        return
      }

      try {
        arguments[1] = createFbEventAction(arguments[1])
        if (arguments[1] === '') {
          return
        }
        switch (arguments.length) {
          case 3:
            fbq(arguments[0], arguments[1], arguments[2])
            break
          case 2:
            fbq(arguments[0], arguments[1])
            break
          case 1:
            fbq(arguments[0])
            break
        }
      } catch (e) {}
    }

    // TikTok Pixel Methods
    function tiktokEventSender(action, data) {
      if (!action || !data) {
        return
      }

      try {
        ttq.track(action, data)
      } catch (e) {}
    }

    function createFbEventAction(action) {
      var fbActions = {
        play: 'TrackPlay',
        pause: 'TrackPause',
        add_to_cart: 'AddToCart',
        removed_from_cart: 'RemovedFromCart',
      }

      return fbActions[action] ? fbActions[action] : action
    }
  }

  analyticsHelper.$inject = ['$location']
  registerFactory(app, 'analyticsHelper', analyticsHelper)
})
</pre></body></html>