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
Message
Author
KaitoSi11
Newbie
Posts: 2
Joined: Sun Sep 08, 2019 9:55 am
Contact:

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?
https://patreon.renpy.org/analytics.html

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 persistent.analytics = 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 persistent.analytics:
            return

        if not tracking_id:
            return

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

        queue.append(urllib.urlencode(kwargs))

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

        `action`
            The action that occurred. A string.

        `label`
            An optional label associated with the event. A string.

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

        """

        kwargs = dict(
            t="event",
            ec=category,
            ea=action)

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

        enqueue(**kwargs)

    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()

        try:
            urllib2.urlopen("https://www.google-analytics.com/batch", data, timeout=10, context=context)
        except:
            if config.developer:
                traceback.print_exc()


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

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

        if not persistent.analytics:
            return

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


    config.interact_callbacks.append(interact_callback)
I tried already and move away from the guide, writing down the key in the analytics.rpy file, but still nothing works.

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

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.

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

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