indiesoftby / defold-yametrica

Defold Engine integration with Yandex.Metrica to track your games on Yandex.Games.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

YaMetrica Cover

Yandex.Metrica for Defold

This is an open-source project. It is not affiliated with Yandex LLC.

Yandex.Metrica is a free of charge web analytics tool for websites, that's the reason why we can use it for HTML5 games. Yandex.Metrica is one of the top three leading web analytics solutions in the world.

Don't be confused with AppMetrica by Yandex - it's an iOS/Android app analytics.

This native extension doesn't implement all Yandex.Metrica functions, but they are enough to track most of the stats of your game.

Supported Platforms

Platform Status
Browser (HTML5) Supported ✅

Installation & Usage

1. Create Yandex.Metrica Tag

You need a Yandex ID in order to work with Yandex.Metrica. If you don't have one, you first need to sign up.

On the page with the list of tags, add a tag. The tag setup page opens. Then fill in the information:

  • Tag name. The specified name is shown on the My tags page and in the upper menu for switching between tags. Use the name of your Defold game.
  • Site URL. Put the address of your game on Yandex.Games like yandex.ru/games/play/123456.

Then accept the Terms of use, click Create a tag. Copy the ID of your counter.

2. Add YaMetrica As Dependency

You can use YaMetrica in your own project by adding this project as a Defold library dependency.

Open your game.project file and in the dependencies field under project add the ZIP file of a specific release.

Then add the following to your game.project file:

[yametrica]
counter_id = PUT_YOUR_COUNTER_ID_HERE

Setting the yametrica.counter_id option initializes Yandex.Metrica SDK in the HTML5 template (take a look at how it's done). From this moment, you can call yametrica.* functions.

3. Call YaMetrica Methods

In your main.script call not_bounce to send information about a non-bounce. It means, for the Yandex.Metrica, that your game finished loading:

function init(self)
    if yametrica then
        yametrica.not_bounce()
    end
end

Then, for every in-game events like scene switching or level ending, call hit:

if yametrica then
    yametrica.hit("#event-name", { title = "Event Name" })
end

Best Practices

Keep in mind that Yandex.Metrica is web analytics for websites, but you are going to use it for an HTML5 game, which is, technically, a single-page website.

  1. Call hit(..) to track significant events in your game: start/end of a level, show/hide of a scene, calling fullscreen ads, etc.
  2. Use anchor identifiers as IDs of events and titles as the name of events: yametrica.hit("#scene-started-introduction", { title: "Scene Started: Introduction" }).
  3. It's crucial to call hit(..) quite often to have a precise Session Length value.

Lua <-> JS

Yandex.Metrica JS SDK YaMetrica Lua API
ym(XXXXXX, 'hit', url[, options]) yametrica.hit(url, [options])
ym(XXXXXX, 'notBounce', [options]) yametrica.not_bounce([options])
ym(XXXXXX, 'params', visitParams[, goalParams]) yametrica.params(visit_params, [goal_params])
ym(XXXXXX, 'reachGoal', target[, params[, callback[, ctx]]]) yametrica.reach_goal(target, [params])
ym(XXXXXX, 'userParams', parameters) yametrica.user_params(parameters)


ym(XXXXXX, 'addFileExtension', extensions) Not implemented
ym(XXXXXX, 'extLink', url[, options]) Not implemented
ym(XXXXXX, 'file', url[, options]) Not implemented
ym(XXXXXX, 'getClientID', function(clientID) { <function body> }) Not implemented
ym(XXXXXX, 'setUserID', "12345") Not implemented

Credits

Artsiom Trubchyk (@aglitchman) is the current YaMetrica owner within Indiesoft and is responsible for the open source repository.

This project uses the source code of CJSON.

License

MIT license.

About

Defold Engine integration with Yandex.Metrica to track your games on Yandex.Games.

License:MIT License


Languages

Language:C 78.7%Language:C++ 9.3%Language:JavaScript 7.2%Language:HTML 2.7%Language:Lua 2.1%