@procore/ai-translations 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1401,6 +1401,7 @@ var aitFunction = async (text, translationRegistry, config2, tool) => {
1401
1401
  };
1402
1402
 
1403
1403
  // src/utils/browser.ts
1404
+ var supportedBrowsers = ["chrome", "arc", "opera"];
1404
1405
  function detectBrowser() {
1405
1406
  const ua = navigator.userAgent;
1406
1407
  if (ua.includes("Arc/")) return "arc";
@@ -1411,6 +1412,10 @@ function detectBrowser() {
1411
1412
  if (ua.includes("Chrome/")) return "chrome";
1412
1413
  return "unknown";
1413
1414
  }
1415
+ function isSupportedBrowser() {
1416
+ const browser = detectBrowser();
1417
+ return supportedBrowsers.includes(browser);
1418
+ }
1414
1419
 
1415
1420
  // src/Provider.tsx
1416
1421
  import { QueryClientProvider, QueryClient } from "@tanstack/react-query";
@@ -1424,7 +1429,12 @@ function AITranslationInnerProvider(props) {
1424
1429
  companyId,
1425
1430
  userId,
1426
1431
  projectId,
1427
- enableAIT = true
1432
+ enableAIT = true,
1433
+ companyLocale,
1434
+ projectLocale,
1435
+ onTrackAnalyticsEvent,
1436
+ page,
1437
+ scope
1428
1438
  } = props;
1429
1439
  const [translationProgress, setTranslationProgress] = useState(null);
1430
1440
  const [modelDownloadProgress, setModelDownloadProgress] = useState(null);
@@ -1501,10 +1511,15 @@ function AITranslationInnerProvider(props) {
1501
1511
  const contextValue = {
1502
1512
  ait,
1503
1513
  locale,
1514
+ companyLocale,
1515
+ projectLocale,
1504
1516
  renderVersion: renderVersionManager.getVersion(),
1505
1517
  translationProgress,
1506
1518
  modelDownloadProgress,
1507
- tool
1519
+ tool,
1520
+ onTrackAnalyticsEvent,
1521
+ page,
1522
+ scope
1508
1523
  };
1509
1524
  return /* @__PURE__ */ jsx(AITranslationContext.Provider, { value: contextValue, children });
1510
1525
  }
@@ -1524,12 +1539,140 @@ function useAITranslation() {
1524
1539
  return ctx;
1525
1540
  }
1526
1541
 
1542
+ // src/hooks/useAIAnalytics.ts
1543
+ import { useContext as useContext2, useCallback as useCallback2 } from "react";
1544
+
1545
+ // src/analytics/events.ts
1546
+ var BUTTON_TYPE = {
1547
+ TRANSLATE: "translate",
1548
+ HIGHLIGHT: "highlight"
1549
+ };
1550
+ var ACTION = {
1551
+ CLICKED: "clicked"
1552
+ };
1553
+ function buildObject(pageContext, buttonType) {
1554
+ return `${pageContext}_${buttonType}_button`;
1555
+ }
1556
+ function buildEventKey(parts) {
1557
+ const { scope, tool, object, action } = parts;
1558
+ return `ux.web.feature.${scope}.${tool}.${object}.${action}`;
1559
+ }
1560
+ function buildAnalyticEvent(params) {
1561
+ const {
1562
+ scope,
1563
+ tool,
1564
+ pageContext,
1565
+ buttonType,
1566
+ baseProperties,
1567
+ action,
1568
+ additionalProperties
1569
+ } = params;
1570
+ const resolvedAction = action ?? ACTION.CLICKED;
1571
+ const object = buildObject(pageContext, buttonType);
1572
+ const key = buildEventKey({
1573
+ scope,
1574
+ tool,
1575
+ object,
1576
+ action: resolvedAction
1577
+ });
1578
+ const properties = {
1579
+ ...baseProperties,
1580
+ ...additionalProperties
1581
+ };
1582
+ return { key, properties };
1583
+ }
1584
+
1585
+ // src/hooks/useAIAnalytics.ts
1586
+ function useAIAnalytics() {
1587
+ const ctx = useContext2(AITranslationContext);
1588
+ if (!ctx) {
1589
+ throw new Error(
1590
+ "useAIAnalytics must be used inside an AITranslationProvider"
1591
+ );
1592
+ }
1593
+ const {
1594
+ locale,
1595
+ companyLocale,
1596
+ projectLocale,
1597
+ tool,
1598
+ page,
1599
+ scope,
1600
+ onTrackAnalyticsEvent
1601
+ } = ctx;
1602
+ const isTrackingEnabled = Boolean(onTrackAnalyticsEvent);
1603
+ const buildBaseProperties = useCallback2(() => {
1604
+ const props = {
1605
+ user_locale: locale,
1606
+ tool,
1607
+ page: page ?? ""
1608
+ };
1609
+ if (companyLocale) props.company_locale = companyLocale;
1610
+ if (projectLocale) props.project_locale = projectLocale;
1611
+ return props;
1612
+ }, [locale, tool, page, companyLocale, projectLocale]);
1613
+ const trackTranslateButtonClicked = useCallback2(
1614
+ (additionalProperties) => {
1615
+ if (!onTrackAnalyticsEvent || !page || !scope) return;
1616
+ onTrackAnalyticsEvent(
1617
+ buildAnalyticEvent({
1618
+ scope,
1619
+ tool,
1620
+ pageContext: page,
1621
+ buttonType: BUTTON_TYPE.TRANSLATE,
1622
+ baseProperties: buildBaseProperties(),
1623
+ additionalProperties
1624
+ })
1625
+ );
1626
+ },
1627
+ [onTrackAnalyticsEvent, tool, page, scope, buildBaseProperties]
1628
+ );
1629
+ const trackHighlightButtonClicked = useCallback2(
1630
+ (additionalProperties) => {
1631
+ if (!onTrackAnalyticsEvent || !page || !scope) return;
1632
+ onTrackAnalyticsEvent(
1633
+ buildAnalyticEvent({
1634
+ scope,
1635
+ tool,
1636
+ pageContext: page,
1637
+ buttonType: BUTTON_TYPE.HIGHLIGHT,
1638
+ baseProperties: buildBaseProperties(),
1639
+ additionalProperties
1640
+ })
1641
+ );
1642
+ },
1643
+ [onTrackAnalyticsEvent, tool, page, scope, buildBaseProperties]
1644
+ );
1645
+ const trackCustomEvent = useCallback2(
1646
+ (buttonType, action, additionalProperties) => {
1647
+ if (!onTrackAnalyticsEvent || !page || !scope) return;
1648
+ onTrackAnalyticsEvent(
1649
+ buildAnalyticEvent({
1650
+ scope,
1651
+ tool,
1652
+ pageContext: page,
1653
+ buttonType,
1654
+ baseProperties: buildBaseProperties(),
1655
+ action,
1656
+ additionalProperties
1657
+ })
1658
+ );
1659
+ },
1660
+ [onTrackAnalyticsEvent, tool, page, scope, buildBaseProperties]
1661
+ );
1662
+ return {
1663
+ trackTranslateButtonClicked,
1664
+ trackHighlightButtonClicked,
1665
+ trackCustomEvent,
1666
+ isTrackingEnabled
1667
+ };
1668
+ }
1669
+
1527
1670
  // src/components/AITranslateText.tsx
1528
1671
  import {
1529
1672
  useState as useState2,
1530
1673
  useEffect as useEffect2,
1531
- useContext as useContext2,
1532
- useCallback as useCallback2,
1674
+ useContext as useContext3,
1675
+ useCallback as useCallback3,
1533
1676
  useRef as useRef2
1534
1677
  } from "react";
1535
1678
 
@@ -1537,8 +1680,8 @@ import {
1537
1680
  import "react";
1538
1681
  import { jsx as jsx2 } from "react/jsx-runtime";
1539
1682
  var TranslatedIcon = ({
1540
- width = 14,
1541
- height = 14,
1683
+ width = 24,
1684
+ height = 24,
1542
1685
  className,
1543
1686
  color = "#000000"
1544
1687
  }) => {
@@ -1556,7 +1699,7 @@ var TranslatedIcon = ({
1556
1699
  "path",
1557
1700
  {
1558
1701
  fill: color,
1559
- d: "M12.87,15.07l-2.54,-2.51 0.03,-0.03c1.74,-1.94 2.98,-4.17 3.71,-6.53L17,6L17,4h-7L10,2L8,2v2L1,4v1.99h11.17C11.5,7.92 10.44,9.75 9,11.35 8.07,10.32 7.3,9.19 6.69,8h-2c0.73,1.63 1.73,3.17 2.98,4.56l-5.09,5.02L4,19l5,-5 3.11,3.11 0.76,-2.04zM18.5,10h-2L12,22h2l1.12,-3h4.75L21,22h2l-4.5,-12zM15.88,17l1.62,-4.33L19.12,17h-3.24z"
1702
+ d: "M12 2C6.48 2 2 6.48 2 12C2 17.52 6.48 22 12 22C17.52 22 22 17.52 22 12C22 6.48 17.52 2 12 2ZM11 19.93C7.05 19.44 4 16.08 4 12C4 11.38 4.08 10.79 4.21 10.21L9 15V16C9 17.1 9.9 18 11 18V19.93ZM17.9 17.39C17.64 16.58 16.9 16 16 16H15V13C15 12.45 14.55 12 14 12H8V10H10C10.55 10 11 9.55 11 9V7H13C14.1 7 15 6.1 15 5V4.59C17.93 5.78 20 8.65 20 12C20 14.08 19.2 15.97 17.9 17.39Z"
1560
1703
  }
1561
1704
  )
1562
1705
  }
@@ -1571,7 +1714,7 @@ var AITranslateText = ({
1571
1714
  showHighlight = false,
1572
1715
  translatedIconProps
1573
1716
  }) => {
1574
- const context = useContext2(AITranslationContext);
1717
+ const context = useContext3(AITranslationContext);
1575
1718
  const [displayText, setDisplayText] = useState2(text ?? "");
1576
1719
  const [showHighlightState, setShowHighlightState] = useState2(showHighlight);
1577
1720
  const eventHandlerRef = useRef2(null);
@@ -1594,7 +1737,7 @@ var AITranslateText = ({
1594
1737
  );
1595
1738
  return () => unsubscribe();
1596
1739
  }, [context, text, showHighlight]);
1597
- const reset = useCallback2(
1740
+ const reset = useCallback3(
1598
1741
  (displayValue = text) => {
1599
1742
  setDisplayText(displayValue);
1600
1743
  setShowHighlightState(false);
@@ -1652,10 +1795,17 @@ var getAITranslationLDId = (domain) => {
1652
1795
  }
1653
1796
  };
1654
1797
  export {
1798
+ ACTION,
1655
1799
  AITranslateText,
1656
1800
  AITranslationProvider,
1657
1801
  AI_TRANSLATION_FEATURE_FLAG_KEY,
1802
+ BUTTON_TYPE,
1803
+ buildAnalyticEvent,
1804
+ buildEventKey,
1805
+ buildObject,
1658
1806
  getAITranslationLDId,
1807
+ isSupportedBrowser,
1808
+ useAIAnalytics,
1659
1809
  useAITranslation,
1660
1810
  useConfig
1661
1811
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@procore/ai-translations",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Library that provides a solution to use AI to translate text into a language",
5
5
  "main": "dist/legacy/index.js",
6
6
  "types": "dist/legacy/index.d.ts",