All files / 3rd-party ThirdPartyIntegrations.tsx

100% Statements 22/22
94.12% Branches 16/17
100% Functions 5/5
100% Lines 21/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46              1x 1x 1x 1x   1x 3x 3x         3x 3x 3x   3x   1x   3x     3x 3x 2x       3x 3x 2x 2x       3x    
/*
 * Copyright 2021 Harness Inc. All rights reserved.
 * Use of this source code is governed by the PolyForm Shield 1.0.0 license
 * that can be found in the licenses directory at the root of this repository, also available at
 * https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt.
 */
 
import React, { useEffect, useMemo } from 'react'
import { useLicenseStore } from 'framework/LicenseStore/LicenseStoreContext'
import { useAppStore } from 'framework/AppStore/AppStoreContext'
import { injectHotJar, identifyHotJarUser } from './HotJar'
 
export const ThirdPartyIntegrations: React.FC = () => {
  const { licenseInformation } = useLicenseStore()
  const { currentUserInfo } = useAppStore()
 
  // HotJar is integrated for non-paid accounts (https://harness.atlassian.net/browse/PLG-946):
  // 		1. Community = window.deploymentType is 'COMMUNITY'
  // 		2. Trial = deploymentType is 'SAAS' AND account does not have any paid module
  const shouldIntegrateHotJar = useMemo(() => {
    const isProd = /^app.harness.io$/i.test(location.hostname)
    const isCommunity = window.deploymentType === 'COMMUNITY'
    const isTrial =
      window.deploymentType === 'SAAS' &&
      licenseInformation &&
      !Object.values(licenseInformation).find(licenseInfo => licenseInfo?.licenseType === 'PAID')
 
    return isProd && !window.hj && (isCommunity || isTrial)
  }, [licenseInformation])
 
  useEffect(() => {
    if (shouldIntegrateHotJar) {
      injectHotJar()
    }
  }, [shouldIntegrateHotJar])
 
  useEffect(() => {
    if (shouldIntegrateHotJar && currentUserInfo) {
      const { email } = currentUserInfo
      identifyHotJarUser(email, { email })
    }
  }, [shouldIntegrateHotJar, currentUserInfo])
 
  return null
}