<h1>PlayFab-Twine</h1>
PlayFab-Twine makes it easy to integrate <a target="_blank" href="https://playfab.com?WT.mc_id=landingpage-playfabtwine-emwalker">PlayFab</a> analytics into your <a target="_blank" href="https://twinery.org">Twine</a> games.
With only a few lines of copy/pasted code, you can get free real-time analytics about how players are interacting with your game or experience!
It specifically targets games built in Twine 2 using the Harlowe story format.
If you're unsure about how analytics can help your narrative game, or want to know how to best use them as a design tool, I've written a <a href="https://dev.to/lazerwalker/using-data-to-improve-your-narrative-games-4g7o">blog post</a> that might be helpful.
Some other questions you might have:
[[What is Twine?|]]
[[What is PlayFab?]]
[[What is PlayFab-Twine?]]
Got a handle on all that? [[Let's get started!|How do I set it up?]]
Since this site is made in Twine, it's using PlayFab-Twine!
If you want to read about how to access analytics, or about how this project respects user privacy, check out the full project README on GitHub: <a target="_blank" href="https://github.com/lazerwalker/playfab-twine">https://github.com/lazerwalker/playfab-twine</a>.<a target="_blank" href="https://twinery.org">Twine</a> is a tool for making hypertext-based interactive fiction — text-based narrative games you play in a web browser by reading text and clicking on links! Twine has a user-friendly visual editor that makes it easy to make games even if you don't know how to program. This website was made in Twine!<a target="_blank" href="https://playfab.com">PlayFab</a> is a hosted backend platform for game LiveOps. In plain English, that means it provides all of the server bits you need to run an online game: things like friend lists and voice chat, an in-game store and inventory management, and leaderboards.
If you're making a Twine game, most of this isn't relevant to you! However, it does include a very good analytics service. Because it's meant for games, it's a better fit fo Twine games than many other non-game analytics tools.
Its free tier is also very generous. If you're just using it to add analytics to your Twine game, it won't cost you anything!PlayFab-Twine is a piece of software that makes it easy for you to add analytics to your Twine game without writing any custom code!
With only a few lines of copy/pasted code, and a tiny bit of configuration, it will automatically gather user behavior for you to look at later. It will:
- Track which passages players visit, and in what order
- Track any number of Twine variables
No identifying data is stored about your players, and their data will not be sold or used in any way.Getting started with PlayFab-Twine is easy!
You'll need to [[sign up for a free PlayFab account|Sign up for PlayFab]] and [[get your Title ID|Get your Title ID]].
If you already know the Title ID you'd like to use, you can jump straight to [[adding the library to your Twine game|integration]].Sign up for a new account at <a href="https://playfab.com?WT.mc_id=github-playfabtwine-emwalker">https://playfab.com</a>.
Once you've created an account and a Studio, create a new Title (this represents a single game).
Next, you'll need to [[find that Title's Title ID|Get your Title ID]]You can find your project's Title ID by clicking the gear in the top-left corner, selecting "Title Settings", and going to the "API Features" tab. It should look something like "A1B2C3".
<img src="images/title-settings.png">
<img src="images/title-id.png">
After you have that, you're ready to [[add PlayFab to your Twine game|integration]].In the Twine editor, edit your game's JavaScript code by opening the menu and selecting "Edit Story JavaScript".
<img src="images/twine-js-menu.png"/>
Paste in the following code, adding in the appropriate Title ID and variable names.
<textarea>
var url = "https://lazerwalker.com/playfab-twine/index.js";
// Your PlayFab Title ID, found in Step 2
var playfabID = "A1B2C3";
// An array of every Twine variable you want to track (don't include the dollar sign)
var trackedVariables = ["score", "hunger", "hasPetDog"];
$(function() {
$.getScript(url, function(data, textStatus, jqxhr) {
const trackedVariables = [];
setupPlayfab(playfabID, trackedVariables, State);
});
});
</textarea>
...and that's it! As soon as your game is live on the web, you can log in at <a target="_blank" href="https://playfab.com?WT.mc_id=github-playfabtwine-emwalker">https://playfab.com</a> and see real-time data flowing in.