Skip to content

Commit

Permalink
updated google analytics tracking functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
nickhudson committed May 26, 2024
1 parent c75867e commit 2119c88
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dark-modeify-me/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</form>
<section id="content" class="hidden">
<nav id="content-nav">
<a class="close" href="#"><img src="./images/close-001.svg" width="36" /></a>
<a class="close" href="#"><img src="./images/close-001.svg" width="36" alt="Clear Content" /></a>
<a id="view-mode" href="#" data-view-mode="design">View Code</a>
</nav>
<iframe id="output"></iframe>
Expand Down
26 changes: 26 additions & 0 deletions dark-modeify-me/scripts/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@ function gtag() {
dataLayer.push(arguments);
}

function trackInput(event='') {
if (event) {
const targ = event?.target,
labels = targ.labels ? targ.labels[0] : undefined;

gtag('event', 'user_input', {
input_type: event?.type,
js_name: event?.constructor.name,
value:
targ.value ||
targ.outerHTML ||
targ.innerHTML ||
targ.alt ||
'input',
description:
targ.innerText ||
targ.outerText ||
labels?.innerText ||
targ.alt ||
targ.name ||
targ.placeholder ||
'N/A'
});
}
}

gtag('js', new Date());
gtag('config', 'G-WMPJ15XJ5M');

Expand Down
16 changes: 11 additions & 5 deletions dark-modeify-me/scripts/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#image handler
from pyodide.http import open_url
from pyodide.ffi import create_proxy, to_js
from js import document, console, alert, Object, FileReader, encodeURIComponent, processHTML
from js import document, console, alert, Object, FileReader, encodeURIComponent, trackInput, processHTML
import base64
from pathlib import Path
#custom scripts
Expand All @@ -22,6 +22,7 @@
'text/html',
'message/rfc822'
]

uploadInput = document.getElementById('upload')
processButton = document.getElementById('process')
downloadButton = document.getElementById('download')
Expand Down Expand Up @@ -74,7 +75,8 @@ async def read_file(e):

reader.onload = onLoadEvent
reader.readAsText(f)


trackInput(e)
return

async def process_file(e):
Expand All @@ -92,6 +94,7 @@ async def process_file(e):
uploadInput.value = ''

processButton.disabled = True
trackInput(e)

if updatedHTML.status == 'error':
if elData.viewMode == 'code':
Expand Down Expand Up @@ -120,6 +123,8 @@ def download_file(e):
tag.click()
document.body.removeChild(tag)

trackInput(e)

def clear_file(e):
e.preventDefault()

Expand All @@ -132,11 +137,13 @@ def clear_file(e):
if viewModeEl.style.visibility == 'hidden':
viewModeEl.style.visibility = 'visible'

trackInput(e)

def change_view(e):
e.preventDefault()

elData = e.target.dataset
fileData = TEMP_FILE[len(TEMP_FILE) - 1]['data']
trackInput(e)

if elData.viewMode == 'design':
elData.viewMode = 'code'
Expand All @@ -155,8 +162,6 @@ async def fetch_req(url):
return response

async def main():
#task = await fetch_req("https://dummyjson.com/products/1")

fileEvent = create_proxy(read_file)
processEvent = create_proxy(process_file)
downloadEvent = create_proxy(download_file)
Expand All @@ -166,6 +171,7 @@ async def main():
uploadInput.accept = ','.join(fileTypes)

# Event Listeners
uploadInput.addEventListener('click', trackInput)
uploadInput.addEventListener('change', fileEvent)
processButton.addEventListener('click', processEvent)
downloadButton.addEventListener('click', downloadEvent)
Expand Down

0 comments on commit 2119c88

Please sign in to comment.