fapitest.py 1.0 KB

1234567891011121314151617181920212223242526272829
  1. from fastapi import FastAPI
  2. import uvicorn
  3. from ga4mp import GtagMP
  4. from ga4mp.store import DictStore
  5. ## ai.choozmo.com
  6. app = FastAPI()
  7. @app.get("/ga")
  8. async def root(utm_source, utm_medium,utm_campaign,utm_term):
  9. print(utm_source)
  10. print(utm_medium)
  11. print(utm_campaign)
  12. print(utm_term)
  13. test_event=None
  14. gtag_tracker=None
  15. gtag_tracker = GtagMP(api_secret='PPx-W5JUQuSgx6B3QZeisA', measurement_id='G-G5H9MMGQFM', client_id=utm_term)
  16. test_event = gtag_tracker.create_new_event(name="edm")
  17. test_event.set_event_param(name="campaign", value=utm_campaign)
  18. test_event.set_event_param(name="email", value=utm_term)
  19. test_event.set_event_param(name="label", value=utm_term)
  20. gtag_tracker.store.set_user_property(name="jtest", value="yes")
  21. event_list = [test_event]
  22. gtag_tracker.send(events=event_list)
  23. return {"message": "Hello World"}
  24. if __name__ == "__main__":
  25. uvicorn.run("fapitest:app", host="0.0.0.0", port=8899)
  26. #http://localhost:8899/ga?utm_source=newsletter&utm_medium=email&utm_campaign=test&utm_term=t2&utm_content=ccc