Google Analytics in RenPy games does not work

In this forum we discuss the future of Ren'Py, both bug fixes and longer-term development. Pre-releases are announced and discussed here.
Post Reply
Posts: 2
Joined: Sun Sep 08, 2019 9:55 am

Google Analytics in RenPy games does not work

#1 Post by KaitoSi11 » Fri Sep 13, 2019 10:29 am

Hey mans, can someone say why this function does not work?

I did everything strictly according to the guide, but nothing is updated on the Google Analytics account. What could be the problem? Is it possible that I missed something?

Code: Select all

# This needs to be set to true to enable analytics.
default = None

# Initialize this to a unique cid.
default persistent.analytics_cid = None

init -10 python in analytics:

    # The google analytics tracking ID.  If not set, no tracking will occur.
    tracking_id = None

    from store import persistent, config
    import uuid
    import threading
    import urllib
    import urllib2
    import ssl

    # Create a cid if needed.
    if persistent.analytics_cid is None:
        persistent.analytics_cid = str(uuid.uuid4())

    # The queue of events that are going to be called. This should not
    # change, as we don't want this to be saved.
    queue = [ ]

    def enqueue(**kwargs):
        if not

        if not tracking_id:

        kwargs["v"] = 1
        kwargs["tid"] = tracking_id
        kwargs["cid"] = persistent.analytics_cid


    def event(category, action, label=None, value=None):
            The category of the event. A string.

            The action that occurred. A string.

            An optional label associated with the event. A string.

            If given, a numeric value associated with the ending. A number.


        kwargs = dict(

        if label is not None:
            kwargs["el"] = label
        if value is not None:
            kwargs["ev"] = value


    def post_events(q):
        This is called in a thread from the interact callback, and is responsible for
        actually posting events to Google Analytics.

        data = "\r\n".join(q) + "\r\n"

        context = ssl._create_unverified_context()

            urllib2.urlopen("", data, timeout=10, context=context)
            if config.developer:

    def interact_callback():
        This is called once per interaction, and then

        q = queue[:]
        queue[:] = [ ]

        if not

        t = threading.Thread(target=post_events, args=(q,))
        t.daemon = True

I tried already and move away from the guide, writing down the key in the analytics.rpy file, but still nothing works.

User avatar
Miko-Class Veteran
Posts: 745
Joined: Tue Jun 22, 2010 12:54 am
Completed: Christmas
IRC Nick: DragoonHP
Location: Zion Island, Solario

Re: Google Analytics in RenPy games does not work

#2 Post by DragoonHP » Sun Dec 22, 2019 8:10 am

It takes a day to update the values on the dashboard.

Posts: 3
Joined: Tue Feb 04, 2020 1:36 pm
Github: Derrizah

Re: Google Analytics in RenPy games does not work

#3 Post by Derrizah » Wed Feb 12, 2020 2:00 pm

Having the same issue. I'm pretty sure I am missing something but no luck finding what. Put tracking ID, added label callback function, played through the game and nothing. Realtime page didn't show anything so I've waited but dashboard does not show anything either.

Post Reply

Who is online

Users browsing this forum: No registered users