Skip to content

Commit

Permalink
created js inject function for analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenaH84 committed Nov 21, 2024
1 parent cff2b71 commit 8b84b5f
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 74 deletions.
4 changes: 2 additions & 2 deletions api/dependencies.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Pkg
Pkg.update()
Pkg.add("HTTP")
Pkg.add(PackageSpec(;name="BattMo", rev="dev"))
Pkg.add(PackageSpec(;name="Jutul", rev="battmo"))
Pkg.add("BattMo")
Pkg.add("Jutul")
Pkg.add("JSON")
Pkg.add("HDF5")
Pkg.add("UUIDs")
Expand Down
58 changes: 29 additions & 29 deletions docker-compose-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,38 +53,38 @@ services:
- app-network
command: streamlit run app.py --global.disableWidgetStateDuplicationWarning true --server.port=8501

umami:
image: docker.umami.is/umami-software/umami:postgresql-latest
container_name: umami
restart: always
environment:
# BASE_PATH: https://app.batterymodel.com/umami
DATABASE_URL: postgres://umami:password@umami-db/umami
DATABASE_TYPE: postgres
HASH_SALT: ${HASH_SALT}
ports:
- "3000:3000"
networks:
- app-network
depends_on:
- umami-db
# umami:
# image: docker.umami.is/umami-software/umami:postgresql-latest
# container_name: umami
# restart: always
# environment:
# # BASE_PATH: https://app.batterymodel.com/umami
# DATABASE_URL: postgres://umami:password@umami-db/umami
# DATABASE_TYPE: postgres
# HASH_SALT: ${HASH_SALT}
# ports:
# - "3000:3000"
# networks:
# - app-network
# depends_on:
# - umami-db

umami-db:
image: postgres:13
container_name: umami-db
restart: always
environment:
POSTGRES_USER: umami
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: umami
networks:
- app-network
volumes:
- umami_db_data:/var/lib/postgresql/data
# umami-db:
# image: postgres:13
# container_name: umami-db
# restart: always
# environment:
# POSTGRES_USER: umami
# POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
# POSTGRES_DB: umami
# networks:
# - app-network
# volumes:
# - umami_db_data:/var/lib/postgresql/data

# Define volumes at the root level, outside of services
volumes:
umami_db_data:
# volumes:
# umami_db_data:

networks:
app-network:
Expand Down
56 changes: 28 additions & 28 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,37 +52,37 @@ services:
- /usr/share/nginx/html/.well-known:/usr/share/nginx/html/.well-known
command: nginx -g 'daemon off;'

umami:
image: docker.umami.is/umami-software/umami:postgresql-latest
container_name: umami
restart: always
environment:
DATABASE_URL: postgres://umami:password@umami-db/umami
DATABASE_TYPE: postgres
HASH_SALT: ${HASH_SALT} # Replace this with a secure, random hash salt
ports:
- "3000:3000"
networks:
- app-network
depends_on:
- umami-db
# umami:
# image: docker.umami.is/umami-software/umami:postgresql-latest
# container_name: umami
# restart: always
# environment:
# DATABASE_URL: postgres://umami:password@umami-db/umami
# DATABASE_TYPE: postgres
# HASH_SALT: ${HASH_SALT} # Replace this with a secure, random hash salt
# ports:
# - "3000:3000"
# networks:
# - app-network
# depends_on:
# - umami-db

umami-db:
image: postgres:13
container_name: umami-db
restart: always
environment:
POSTGRES_USER: umami
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} # Replace with a strong password
POSTGRES_DB: umami
networks:
- app-network
volumes:
- umami_db_data:/var/lib/postgresql/data
# umami-db:
# image: postgres:13
# container_name: umami-db
# restart: always
# environment:
# POSTGRES_USER: umami
# POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} # Replace with a strong password
# POSTGRES_DB: umami
# networks:
# - app-network
# volumes:
# - umami_db_data:/var/lib/postgresql/data

# Define volumes at the root level, outside of services
volumes:
umami_db_data:
# volumes:
# umami_db_data:

networks:
app-network:
Expand Down
32 changes: 32 additions & 0 deletions gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from PIL import Image
from app_scripts import app_access
import streamlit.components.v1 as components
import pathlib
from bs4 import BeautifulSoup
import shutil


##############################
Expand Down Expand Up @@ -52,6 +55,35 @@
# )


def inject_ga():
UM_ID = "adcac53d-bc65-4ca3-9f98-be5c7c4ee75d"

UM_JS = """
<script defer src="https://cloud.umami.is/script.js" data-website-id="adcac53d-bc65-4ca3-9f98-be5c7c4ee75d"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js, new Date());
gtag('config', 'adcac53d-bc65-4ca3-9f98-be5c7c4ee75d');
<script>
"""

# Insert script into the index.html file
index_path = pathlib.Path(st.__file__).parent / "static" / "index.html"
soup = BeautifulSoup(index_path.read_text(), features="html.parser")
if not soup.find(id=UM_ID):
bck_index = index_path.with_suffix('.bck')
if bck_index.exists():
shutil.copy(bck_index, index_path)
else:
shutil.copy(index_path, bck_index)
html = str(soup)
new_html = html.replace('<head>', '<head>\n' + UM_JS)
index_path.write_text(new_html)


inject_ga()

##############################
# Remember user changed values
for k, v in st.session_state.items():
Expand Down
Binary file modified gui/output_files/battmo_results.hdf5
Binary file not shown.
3 changes: 2 additions & 1 deletion gui/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ st-theme
scipy
streamlit-navigation-bar
websocket-client
websocat
websocat
bs4
28 changes: 14 additions & 14 deletions nginx/project.conf
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ server {
proxy_set_header X-Forwarded-Proto $scheme;
}

location /umami.js {
proxy_pass http://umami:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# location /umami.js {
# proxy_pass http://umami:3000;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
# }

location /api/collect {
proxy_pass http://umami:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# location /api/collect {
# proxy_pass http://umami:3000;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
# }

# Umami analytics application proxy
# location /umami/ {
Expand Down

0 comments on commit 8b84b5f

Please sign in to comment.