GA4 HF Envs
Browse files- autenticacion.py +8 -4
- ga4Analiticas.py +5 -7
- globales.py +3 -3
- main.py +1 -2
autenticacion.py
CHANGED
|
@@ -6,17 +6,19 @@ def defineAmbiente(env):
|
|
| 6 |
|
| 7 |
print("Estoy en defineambiente...")
|
| 8 |
if local_check():
|
| 9 |
-
print("Entorno Local...")
|
| 10 |
-
|
| 11 |
import bridges
|
| 12 |
if env == 'prod':
|
| 13 |
llave = bridges.llave_prod
|
| 14 |
webhook = bridges.webhook_prod
|
| 15 |
firestore = 'config_prod.json'
|
|
|
|
|
|
|
| 16 |
else: #if dev
|
| 17 |
llave = bridges.llave_sandbox
|
| 18 |
webhook = bridges.webhook_sandbox
|
| 19 |
firestore = 'config_dev.json'
|
|
|
|
| 20 |
else:
|
| 21 |
print("Entorno remoto listo...")
|
| 22 |
if os.getenv("ambiente_stripe") == 'prod':
|
|
@@ -24,13 +26,15 @@ def defineAmbiente(env):
|
|
| 24 |
llave = os.getenv("STRIPE_KEY_PROD") #Acceso a HF
|
| 25 |
webhook = os.getenv("STRIPE_WEBHOOK_SECRET_PROD")
|
| 26 |
config_creator.creaConfigFirestore('configuracion_prod') #La secret var de HF respecto a prod.
|
|
|
|
| 27 |
else: #if dev
|
| 28 |
print("Ambiente stripe es: ", os.getenv("ambiente_stripe"))
|
| 29 |
llave = os.getenv("STRIPE_KEY_SANDBOX") #Acceso a HF
|
| 30 |
webhook = os.getenv("STRIPE_WEBHOOK_SECRET_SANDBOX")
|
| 31 |
config_creator.creaConfigFirestore('configuracion_dev') #La secret var de HF respecto a dev.
|
| 32 |
-
|
| 33 |
-
|
|
|
|
| 34 |
|
| 35 |
def local_check():
|
| 36 |
hostname = socket.gethostname()
|
|
|
|
| 6 |
|
| 7 |
print("Estoy en defineambiente...")
|
| 8 |
if local_check():
|
| 9 |
+
print("Entorno Local...")
|
|
|
|
| 10 |
import bridges
|
| 11 |
if env == 'prod':
|
| 12 |
llave = bridges.llave_prod
|
| 13 |
webhook = bridges.webhook_prod
|
| 14 |
firestore = 'config_prod.json'
|
| 15 |
+
#ga4Key = bridges.GA4_API_SECRET_SPLASH
|
| 16 |
+
|
| 17 |
else: #if dev
|
| 18 |
llave = bridges.llave_sandbox
|
| 19 |
webhook = bridges.webhook_sandbox
|
| 20 |
firestore = 'config_dev.json'
|
| 21 |
+
ga4Key = bridges.GA4_API_SECRET_TARGET
|
| 22 |
else:
|
| 23 |
print("Entorno remoto listo...")
|
| 24 |
if os.getenv("ambiente_stripe") == 'prod':
|
|
|
|
| 26 |
llave = os.getenv("STRIPE_KEY_PROD") #Acceso a HF
|
| 27 |
webhook = os.getenv("STRIPE_WEBHOOK_SECRET_PROD")
|
| 28 |
config_creator.creaConfigFirestore('configuracion_prod') #La secret var de HF respecto a prod.
|
| 29 |
+
ga4Key = os.getenv("GA4_SECRET_PROD")
|
| 30 |
else: #if dev
|
| 31 |
print("Ambiente stripe es: ", os.getenv("ambiente_stripe"))
|
| 32 |
llave = os.getenv("STRIPE_KEY_SANDBOX") #Acceso a HF
|
| 33 |
webhook = os.getenv("STRIPE_WEBHOOK_SECRET_SANDBOX")
|
| 34 |
config_creator.creaConfigFirestore('configuracion_dev') #La secret var de HF respecto a dev.
|
| 35 |
+
ga4Key = os.getenv("GA4_SECRET_DEV")
|
| 36 |
+
|
| 37 |
+
return llave, webhook, ga4Key
|
| 38 |
|
| 39 |
def local_check():
|
| 40 |
hostname = socket.gethostname()
|
ga4Analiticas.py
CHANGED
|
@@ -1,10 +1,8 @@
|
|
| 1 |
-
import requests
|
| 2 |
import json
|
| 3 |
-
import
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
GA4_API_SECRET = "zqxXw6mdR1CR0FaQYWaZEQ" # Reemplaza con tu secreto
|
| 7 |
-
GA4_MEASUREMENT_ID = "G-PHPJCWFF9L" # Reemplaza con tu ID de medición
|
| 8 |
|
| 9 |
def send_ga4_purchase_event(session):
|
| 10 |
"""
|
|
@@ -13,7 +11,7 @@ def send_ga4_purchase_event(session):
|
|
| 13 |
Args:
|
| 14 |
event_data: Un diccionario con los datos del evento de compra de Stripe.
|
| 15 |
"""
|
| 16 |
-
url = f"https://www.google-analytics.com/mp/collect?measurement_id={GA4_MEASUREMENT_ID}&api_secret={
|
| 17 |
|
| 18 |
moneda = session['currency'].upper()
|
| 19 |
imagenes = session['metadata']['imagenes']
|
|
@@ -53,7 +51,7 @@ def send_ga4_purchase_event(session):
|
|
| 53 |
{
|
| 54 |
"name": "purchase",
|
| 55 |
"params": {
|
| 56 |
-
"debug_mode": True,
|
| 57 |
"transaction_id": session['id'],
|
| 58 |
"value": valor, # Convierte de céntimos a la unidad de moneda
|
| 59 |
"currency": moneda,
|
|
|
|
|
|
|
| 1 |
import json
|
| 2 |
+
import requests
|
| 3 |
+
import globales
|
| 4 |
|
| 5 |
+
GA4_MEASUREMENT_ID = "G-PHPJCWFF9L"
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def send_ga4_purchase_event(session):
|
| 8 |
"""
|
|
|
|
| 11 |
Args:
|
| 12 |
event_data: Un diccionario con los datos del evento de compra de Stripe.
|
| 13 |
"""
|
| 14 |
+
url = f"https://www.google-analytics.com/mp/collect?measurement_id={GA4_MEASUREMENT_ID}&api_secret={globales.ga4Key}"
|
| 15 |
|
| 16 |
moneda = session['currency'].upper()
|
| 17 |
imagenes = session['metadata']['imagenes']
|
|
|
|
| 51 |
{
|
| 52 |
"name": "purchase",
|
| 53 |
"params": {
|
| 54 |
+
#"debug_mode": True,
|
| 55 |
"transaction_id": session['id'],
|
| 56 |
"value": valor, # Convierte de céntimos a la unidad de moneda
|
| 57 |
"currency": moneda,
|
globales.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import autenticacion
|
| 2 |
|
| 3 |
env = 'dev' #o dev
|
| 4 |
-
llave, webhook = autenticacion.defineAmbiente(env)
|
| 5 |
|
| 6 |
-
print("La llave es: ", llave)
|
| 7 |
-
print("Y el webhook es: ", webhook)
|
|
|
|
| 1 |
import autenticacion
|
| 2 |
|
| 3 |
env = 'dev' #o dev
|
| 4 |
+
llave, webhook, ga4Key = autenticacion.defineAmbiente(env)
|
| 5 |
|
| 6 |
+
# print("La llave es: ", llave)
|
| 7 |
+
# print("Y el webhook es: ", webhook)
|
main.py
CHANGED
|
@@ -1,9 +1,8 @@
|
|
| 1 |
import stripe
|
| 2 |
import globales
|
| 3 |
import herramientas
|
| 4 |
-
from fastapi import FastAPI, Request, Header
|
| 5 |
import ga4Analiticas
|
| 6 |
-
|
| 7 |
|
| 8 |
app = FastAPI()
|
| 9 |
|
|
|
|
| 1 |
import stripe
|
| 2 |
import globales
|
| 3 |
import herramientas
|
|
|
|
| 4 |
import ga4Analiticas
|
| 5 |
+
from fastapi import FastAPI, Request, Header
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|