Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Help with Using Google Analytics to track page views with Twine 2.0

I'm having difficulty using this example of code to link my hypertext to my Google Analytics account: https://groups.google.com/forum/#!topic/tweecode/ENbun6TbfiI

The tutorial is very useful and accomplishes exactly what I want to do, however when it gives as the example of using a macro to track each passage, it's suitable for Twine 1.0:

<<set ga('send', 'event', 'passage', 'loaded', 'PASSAGE NAME HERE'); >>

When I try and write this for Twine 2.0 Harlow, I write it as:

(set: ga('send', 'event', 'passage', 'loaded', 'Introduction'))

But when I try and run this, the notification I get is:

The (set:) macro needs 1 more value.
The (set:) macro must only be given an assignment operation


Is there something wrong with my code here, or does the problem lie somewhere else?

Does an alternative way exist of using Google Analytics and tracking events with Twine 2.0?

Comments

  • Did you ever figure this out? I'm working on a Twine2 game and I would like to use Google Analytics with it.
  • You're working on a Harlowe game, apparently. Twine 2 is the compiler/IDE, Harlowe is simply the default story format in Twine 2.

    For Harlowe: I believe that the <script> tag is available in current versions of Harlowe, so you should be able to do something like the following:
    <script>ga("send", "event", "passage", "loaded", "PASSAGE NAME HERE");</script>
    

    For Snowman:
    <% ga("send", "event", "passage", "loaded", "PASSAGE NAME HERE"); %>
    

    For SugarCube:
    <<script>>ga("send", "event", "passage", "loaded", "PASSAGE NAME HERE");<</script>>
    
  • I came across the same issue. The MadExile is correct that for Harlowe the <script> tag works. I would like to add that for me I didn't work to paste the google analytics code as described in the complete guide Owenfrog refers to into a passage. I had to paste this into the "Story JavaScript" to make it work (without the <script></script>).

    I am adding my test file so other people can see how it works. An alternative might be
    http://blog.ivybaumgarten.com/twine-macros-for-google-drive-spreadsheets/
Sign In or Register to comment.