From a10b49e428442b3140bdbaf56ffaab405f486dd9 Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Tue, 26 Nov 2024 14:14:48 -0800 Subject: [PATCH 1/3] update hubpost tracking form submission --- backend/danswer/auth/users.py | 24 ++++++++++---- backend/danswer/configs/app_configs.py | 22 ++++++++++--- backend/ee/danswer/configs/app_configs.py | 3 ++ .../ee/danswer/server/tenants/provisioning.py | 32 +++++++++++++++++++ web/src/lib/constants.ts | 4 +-- 5 files changed, 72 insertions(+), 13 deletions(-) diff --git a/backend/danswer/auth/users.py b/backend/danswer/auth/users.py index cf3de018f4b..470ba1c994c 100644 --- a/backend/danswer/auth/users.py +++ b/backend/danswer/auth/users.py @@ -229,9 +229,16 @@ async def create( safe: bool = False, request: Optional[Request] = None, ) -> User: - referral_source = None - if request is not None: - referral_source = request.cookies.get("referral_source", None) + referral_source = ( + request.cookies.get("referral_source", None) + if request is not None + else None + ) + if referral_source: + await fetch_ee_implementation_or_noop( + "danswer.server.tenants.provisioning", + "submit_to_hubspot", + )(user_create.email, referral_source, request) tenant_id = await fetch_ee_implementation_or_noop( "danswer.server.tenants.provisioning", @@ -297,9 +304,14 @@ async def oauth_callback( associate_by_email: bool = False, is_verified_by_default: bool = False, ) -> User: - referral_source = None - if request: - referral_source = getattr(request.state, "referral_source", None) + referral_source = ( + getattr(request.state, "referral_source", None) if request else None + ) + if referral_source: + await fetch_ee_implementation_or_noop( + "danswer.server.tenants.provisioning", + "submit_to_hubspot", + )(account_email, referral_source, request) tenant_id = await fetch_ee_implementation_or_noop( "danswer.server.tenants.provisioning", diff --git a/backend/danswer/configs/app_configs.py b/backend/danswer/configs/app_configs.py index e06d3f5c420..fdae0b1a790 100644 --- a/backend/danswer/configs/app_configs.py +++ b/backend/danswer/configs/app_configs.py @@ -119,14 +119,25 @@ VESPA_PORT = os.environ.get("VESPA_PORT") or "8081" VESPA_TENANT_PORT = os.environ.get("VESPA_TENANT_PORT") or "19071" -VESPA_CLOUD_URL = os.environ.get("VESPA_CLOUD_URL", "") +VESPA_CLOUD_URL = "https://c1035a2b.bfae05b9.z.vespa-app.cloud" +# VESPA_CLOUD_URL ="https://cdd1b4e2.caaeaf88.z.vespa-app.cloud" + + +# os.environ.get("VESPA_CLOUD_URL", "") # The default below is for dockerized deployment VESPA_DEPLOYMENT_ZIP = ( os.environ.get("VESPA_DEPLOYMENT_ZIP") or "/app/danswer/vespa-app.zip" ) -VESPA_CLOUD_CERT_PATH = os.environ.get("VESPA_CLOUD_CERT_PATH") -VESPA_CLOUD_KEY_PATH = os.environ.get("VESPA_CLOUD_KEY_PATH") +VESPA_CLOUD_CERT_PATH = ( + "/Users/danswer-trial/.vespa/testdanswer.onyx.default/data-plane-public-cert.pem" +) +VESPA_CLOUD_KEY_PATH = ( + "/Users/danswer-trial/.vespa/testdanswer.onyx.default/data-plane-private-key.pem" +) + +# VESPA_CLOUD_CERT_PATH = os.environ.get("VESPA_CLOUD_CERT_PATH") +# VESPA_CLOUD_KEY_PATH = os.environ.get("VESPA_CLOUD_KEY_PATH") # Number of documents in a batch during indexing (further batching done by chunks before passing to bi-encoder) try: @@ -448,7 +459,7 @@ os.environ.get("CUSTOM_ANSWER_VALIDITY_CONDITIONS", "[]") ) -VESPA_REQUEST_TIMEOUT = int(os.environ.get("VESPA_REQUEST_TIMEOUT") or "15") +VESPA_REQUEST_TIMEOUT = int(os.environ.get("VESPA_REQUEST_TIMEOUT") or "1000") SYSTEM_RECURSION_LIMIT = int(os.environ.get("SYSTEM_RECURSION_LIMIT") or "1000") @@ -473,7 +484,8 @@ # Use managed Vespa (Vespa Cloud). If set, must also set VESPA_CLOUD_URL, VESPA_CLOUD_CERT_PATH and VESPA_CLOUD_KEY_PATH -MANAGED_VESPA = os.environ.get("MANAGED_VESPA", "").lower() == "true" +MANAGED_VESPA = True +# os.environ.get("MANAGED_VESPA", "").lower() == "true" ENABLE_EMAIL_INVITES = os.environ.get("ENABLE_EMAIL_INVITES", "").lower() == "true" diff --git a/backend/ee/danswer/configs/app_configs.py b/backend/ee/danswer/configs/app_configs.py index 7e1ade5f3a2..031aff1dd39 100644 --- a/backend/ee/danswer/configs/app_configs.py +++ b/backend/ee/danswer/configs/app_configs.py @@ -19,3 +19,6 @@ OPENAI_DEFAULT_API_KEY = os.environ.get("OPENAI_DEFAULT_API_KEY") ANTHROPIC_DEFAULT_API_KEY = os.environ.get("ANTHROPIC_DEFAULT_API_KEY") COHERE_DEFAULT_API_KEY = os.environ.get("COHERE_DEFAULT_API_KEY") + + +HUBSPOT_TRACKING_URL = os.environ.get("HUBSPOT_TRACKING_URL") diff --git a/backend/ee/danswer/server/tenants/provisioning.py b/backend/ee/danswer/server/tenants/provisioning.py index 1cc07210e56..bdd96f8c912 100644 --- a/backend/ee/danswer/server/tenants/provisioning.py +++ b/backend/ee/danswer/server/tenants/provisioning.py @@ -3,7 +3,9 @@ import uuid import aiohttp # Async HTTP client +import httpx from fastapi import HTTPException +from fastapi import Request from sqlalchemy import select from sqlalchemy.orm import Session @@ -26,6 +28,7 @@ from danswer.setup import setup_danswer from ee.danswer.configs.app_configs import ANTHROPIC_DEFAULT_API_KEY from ee.danswer.configs.app_configs import COHERE_DEFAULT_API_KEY +from ee.danswer.configs.app_configs import HUBSPOT_TRACKING_URL from ee.danswer.configs.app_configs import OPENAI_DEFAULT_API_KEY from ee.danswer.server.tenants.access import generate_data_plane_token from ee.danswer.server.tenants.models import TenantCreationPayload @@ -267,3 +270,32 @@ def configure_default_api_keys(db_session: Session) -> None: logger.info( "COHERE_DEFAULT_API_KEY not set, skipping Cohere embedding provider configuration" ) + + +async def submit_to_hubspot( + email: str, referral_source: str | None, request: Request +) -> None: + # Get the HubSpot tracking cookie + hubspot_cookie = request.cookies.get("hubspotutk") + + # Get the user's IP address + ip_address = request.client.host if request.client else None + + data = { + "fields": [ + {"name": "email", "value": email}, + {"name": "referral_source", "value": referral_source or ""}, + ], + "context": { + "hutk": hubspot_cookie, + "ipAddress": ip_address, + "pageUri": str(request.url), + "pageName": "User Registration", + }, + } + + async with httpx.AsyncClient() as client: + response = await client.post(HUBSPOT_TRACKING_URL, json=data) + + if response.status_code != 200: + logger.error(f"Failed to submit to HubSpot: {response.text}") diff --git a/web/src/lib/constants.ts b/web/src/lib/constants.ts index e8037764adc..da112818bda 100644 --- a/web/src/lib/constants.ts +++ b/web/src/lib/constants.ts @@ -62,8 +62,8 @@ export const CUSTOM_ANALYTICS_ENABLED = process.env.CUSTOM_ANALYTICS_SECRET_KEY ? true : false; -export const GTM_ENABLED = - process.env.NEXT_PUBLIC_GTM_ENABLED?.toLowerCase() === "true"; +export const GTM_ENABLED = true; +// process.env.NEXT_PUBLIC_GTM_ENABLED?.toLowerCase() === "true"; export const DISABLE_LLM_DOC_RELEVANCE = process.env.DISABLE_LLM_DOC_RELEVANCE?.toLowerCase() === "true"; From 4e402960b97f634881daf57d2370d8fd83ac4bf4 Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Tue, 26 Nov 2024 14:16:07 -0800 Subject: [PATCH 2/3] validate --- backend/danswer/configs/app_configs.py | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/backend/danswer/configs/app_configs.py b/backend/danswer/configs/app_configs.py index fdae0b1a790..e06d3f5c420 100644 --- a/backend/danswer/configs/app_configs.py +++ b/backend/danswer/configs/app_configs.py @@ -119,25 +119,14 @@ VESPA_PORT = os.environ.get("VESPA_PORT") or "8081" VESPA_TENANT_PORT = os.environ.get("VESPA_TENANT_PORT") or "19071" -VESPA_CLOUD_URL = "https://c1035a2b.bfae05b9.z.vespa-app.cloud" -# VESPA_CLOUD_URL ="https://cdd1b4e2.caaeaf88.z.vespa-app.cloud" - - -# os.environ.get("VESPA_CLOUD_URL", "") +VESPA_CLOUD_URL = os.environ.get("VESPA_CLOUD_URL", "") # The default below is for dockerized deployment VESPA_DEPLOYMENT_ZIP = ( os.environ.get("VESPA_DEPLOYMENT_ZIP") or "/app/danswer/vespa-app.zip" ) -VESPA_CLOUD_CERT_PATH = ( - "/Users/danswer-trial/.vespa/testdanswer.onyx.default/data-plane-public-cert.pem" -) -VESPA_CLOUD_KEY_PATH = ( - "/Users/danswer-trial/.vespa/testdanswer.onyx.default/data-plane-private-key.pem" -) - -# VESPA_CLOUD_CERT_PATH = os.environ.get("VESPA_CLOUD_CERT_PATH") -# VESPA_CLOUD_KEY_PATH = os.environ.get("VESPA_CLOUD_KEY_PATH") +VESPA_CLOUD_CERT_PATH = os.environ.get("VESPA_CLOUD_CERT_PATH") +VESPA_CLOUD_KEY_PATH = os.environ.get("VESPA_CLOUD_KEY_PATH") # Number of documents in a batch during indexing (further batching done by chunks before passing to bi-encoder) try: @@ -459,7 +448,7 @@ os.environ.get("CUSTOM_ANSWER_VALIDITY_CONDITIONS", "[]") ) -VESPA_REQUEST_TIMEOUT = int(os.environ.get("VESPA_REQUEST_TIMEOUT") or "1000") +VESPA_REQUEST_TIMEOUT = int(os.environ.get("VESPA_REQUEST_TIMEOUT") or "15") SYSTEM_RECURSION_LIMIT = int(os.environ.get("SYSTEM_RECURSION_LIMIT") or "1000") @@ -484,8 +473,7 @@ # Use managed Vespa (Vespa Cloud). If set, must also set VESPA_CLOUD_URL, VESPA_CLOUD_CERT_PATH and VESPA_CLOUD_KEY_PATH -MANAGED_VESPA = True -# os.environ.get("MANAGED_VESPA", "").lower() == "true" +MANAGED_VESPA = os.environ.get("MANAGED_VESPA", "").lower() == "true" ENABLE_EMAIL_INVITES = os.environ.get("ENABLE_EMAIL_INVITES", "").lower() == "true" From c4a8a97d23f04388c904f4294f090388e86a7319 Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Tue, 26 Nov 2024 14:17:42 -0800 Subject: [PATCH 3/3] finalize --- backend/ee/danswer/server/tenants/provisioning.py | 8 ++++++-- web/src/lib/constants.ts | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/backend/ee/danswer/server/tenants/provisioning.py b/backend/ee/danswer/server/tenants/provisioning.py index bdd96f8c912..3db28ee3ec4 100644 --- a/backend/ee/danswer/server/tenants/provisioning.py +++ b/backend/ee/danswer/server/tenants/provisioning.py @@ -275,10 +275,14 @@ def configure_default_api_keys(db_session: Session) -> None: async def submit_to_hubspot( email: str, referral_source: str | None, request: Request ) -> None: - # Get the HubSpot tracking cookie + if not HUBSPOT_TRACKING_URL: + logger.info("HUBSPOT_TRACKING_URL not set, skipping HubSpot submission") + return + + # HubSpot tracking cookie hubspot_cookie = request.cookies.get("hubspotutk") - # Get the user's IP address + # IP address ip_address = request.client.host if request.client else None data = { diff --git a/web/src/lib/constants.ts b/web/src/lib/constants.ts index da112818bda..e8037764adc 100644 --- a/web/src/lib/constants.ts +++ b/web/src/lib/constants.ts @@ -62,8 +62,8 @@ export const CUSTOM_ANALYTICS_ENABLED = process.env.CUSTOM_ANALYTICS_SECRET_KEY ? true : false; -export const GTM_ENABLED = true; -// process.env.NEXT_PUBLIC_GTM_ENABLED?.toLowerCase() === "true"; +export const GTM_ENABLED = + process.env.NEXT_PUBLIC_GTM_ENABLED?.toLowerCase() === "true"; export const DISABLE_LLM_DOC_RELEVANCE = process.env.DISABLE_LLM_DOC_RELEVANCE?.toLowerCase() === "true";