What I’m trying to do:
App: https://quiet-droopy-pension.anvil.app
Implement Segment tracking on my app to send event when someone clicks a tab (link). Currently, it keeps returning the error “AttributeError: ‘Window’ object has no attribute ‘analytics’”.
What I’ve tried and what’s not working:
- I have tried changing the Segment script according to this post:
AttributeError: 'list' object has no attribute 'track' (Connecting to Segment) - #7 - I have added the HTML asset with the segment script
- I tried to follow the tutorial here: https:// anvil.works/ articles/ segment-tracking
- I have tried ChatGPT without success
Code Sample:
# this is a formatted code snippet.
from ._anvil_designer import MainFormTemplate
from anvil import *
from .TabForm1 import TabForm1
from .TabForm2 import TabForm2
from .TabForm3 import TabForm3
from anvil.js import window
class MainForm(MainFormTemplate):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
# Any code you write here will run when the form opens.
def tab_click(self, **event_args):
window.analytics.track("trackClick")
sender = event_args.get("sender", None)
[....]
# paste your code between ```
Additional note: @stucork here is the new post, hoping it’s clearer.
Any help is appreciated, thank you