
The article is aimed at novice developers who want to run their application in a social network.
The article describes the personal experience of creating an IFrame application, from scratch, for Vkontakte, as well as all the events that occurred during the launch and after, and, of course, the errors made. You can even say that this is not really an article, but rather a story.
In addition to the story, there are load reports, an attempt to monetize, server information and code analysis. Therefore, you can switch to your points of interest.
The application as an example will be a snake, with a slight modification.
Impatient, link:
vk.com/classic_snakeHere you can change the code (no user rating):
js.do/usr753/snake')
Content
A bit of historyFirst problemsMonetizationServer, Application, LoadApplication processSnake insideWhat awaits you after the publication of the applicationfindingsA bit of history
A few months ago, on Habré, there was a series of posts with the title "Playing 30 lines of code." And it so happened that I came across this post
http://habrahabr.ru/post/202476/ there described the creation of a simple snake, not having had time to finish reading it to the end, I rushed to write my own. And as I wrote, I played a little and abandoned the case for a long time.
But soon, he was eager to try himself in a new sphere, in the development of applications for social networks. Moreover, the game was already ready and gathering dust in a dark, forgotten directory. And the platform itself promised such nishtyak as - access to a large audience, zero costs for promotion (under certain conditions). Convenient API and monetization, in many ways.
It remains only to modify and download, which I actually did.
First problems
After adding the application to VKontakte, it is available for installation by a direct link, but is not available in the search and is not displayed in the general directory.
On the account you need to have 10 votes (local currency VK, 10 votes == 70 rubles), in order to send the application for moderation, if everything is normal and it complies with the rules, it is added to the catalog of new applications, and the written off votes are returned back. And if something is wrong, your 10 votes will not be returned. The application can be sent again, after eliminating the inconsistencies.
After the application has successfully passed the moderation, it gets to the third position in the directory of new applications and then goes down, and soon disappears completely. The first two positions, in new applications, seem to be paid and cost about 1000 votes.
There are still unspoken rules that are not written anywhere, they can only be learned from the verifier.
Sent the game to moderation. I did not have to wait a long time for an answer:

And here I had to study their API, write a rating script that interacts with my database and an additional module on JS. Thus, my test application from a single file evolved into a not entirely simple one. The application itself was engaged in free time. When I did everything I needed, I sent it for a second check, and went to bed.
When I woke up in the morning, I saw a text message coming up: “Your application has been approved and added to the directory ... and something else there.”

Immediately rushed to watch. The game was installed by 57 people, after a minute it updated the page - 100 people, 200, 300, 400. I spent the whole day pressing F5. By evening, there were about 2000 people who installed the application. The next day, twice as many. After a couple of days, the excitement was already gone and the participants were perceived as simple numbers. By the way, the moderator returned 10 votes, thanks to him more.

Monetization
The application was considered a test and its monetization was not planned. After a couple of weeks I decided to hang ads from VK partners, chose a preloader (pop-up ads before downloading the application). It is not allowed to choose an advertising partner, but only from the list of recommended ones.
At that moment, the application itself went down and there was no such influx of the audience as before. When the advertisement was hung there were about 2,000 unique visitors per day, the next day was 1,700 and less and less every day. Now, the game is not in new applications, i.e. It does not weigh on the main one as before, but it can be raised for 1000 votes.
After a couple of weeks, after the application disappeared from the main page, 50-250 people visit it daily. The same is the influx of the audience, but a small, 5-20 people a day.
The graph shows how people find it:

It also happens that people delete the application.

And the earnings from the preloader for 2 months amounted to 76 rubles, for 4500 hits.
But the preloader itself is not shown to everyone, but only if the user fits “certain parameters”, which is 40-60% of the audience. These parameters are set by the advertiser, thereby choosing "his" target audience, which will be shown advertising.
These parameters include: interests, tastes, books, your music, your browser and all that you yourself indicated on your page. In a word - Targeting.

Server, Application, Load
The server was a simple VPS with the following characteristics:
Debian 32-bit, RAM: 512mb, CPU: 500Mhz * 2 - all this for 210 rubles per month.
Installed software:
Nginx - to distribute statics, and for data processing, nginx redirects requests to Apache2 + PHP + MySQL.
The game itself is written in HTML (4.0) + JavaScript and some CSS, without the use of frameworks and without different libraries.
All this was collected from different js / css modules into one file and passed through YUI Compressor for compression. As a result, there was one html file weighing 20-30kb, a full-fledged game with a rating + a couple of pictures, one for the background, the second - a loader, for displaying the download.
These few kilobytes gave more than one and a half gigabytes of traffic. According to this, if your application weighs a lot, get ready to pay for traffic.
Visitors for all time:

As for the load, the maximum number of visitors per day was 6 thousand people.

Maybe for some it is not enough, but I honestly did not expect that the server will survive. I was frightened by various articles that they say the server needed cool. And as it turned out, this “a lot” is used by 5-20% of resources out of 100.

The processor load did not rise above 12% and then, if it went up for a second and immediately became 0%, it usually jumps from 0 to 4%.
And the use of RAM did not exceed 200MB, even when the InnoDB buffer with 8mb raised to 32mb, just in case.
Perhaps such indicators due to the following application architecture, or because of undemanding operations.
Application process
After the user enters the page, he downloads one html-file (game), then ajax receives a list of users (Top100, 5kb in size), his position in the rating and the score, all in XML.
Then everything happens on the same page, nothing else is loaded from the server.
The user can re-request the updated data of other participants, by pressing the button, or send their result to the server.
After that, when the xml-list came to the client, with a score and identifier of VK users, a rating is formed. We request data, through the API, of the first 10 users. And we deduce: "Name + Surname and their total score." If the user has clicked on the “next” button, then a new access to the API occurs, and we don’t overwrite the old data, but cache them, i.e. we will not re-access the API if we have previously received this data. And in the database itself, we store their id'shniki, invoice and other technical information.

Still, the main thing is to adjust the indexes so that the data is taken from there, and not read from the disk.
Snake inside
Let me remind you that this is a "snake", then its code will be dealt with. If you decide to write a snake yourself, you can skip this paragraph, otherwise you will get it in the well-known phrase: “the killer is the butler”.
Very few people will get into the code, for this I will describe the algorithm first, and then look at the code as well.
First, a field is generated from simple divs. Coordinates are listed as div identifiers that allow you to access any cell. Next, create a snake on this field, by highlighting the cells, color and put the coordinates of the snake body into a multidimensional array.
Then a bonus (snake food) is created. Again, save the coordinates of the bonus to the array.
After that, when the bonus is eaten, we collect empty cells into an array (without the cells on which the snake itself is located) and from them, we choose a different cell at random, and already make it a bonus. If empty cells are not detected then the user is the winner.
When moving, in the array, we change only two cells, the back one is removed, and the front one (unused by the snake), in the direction of movement we paint in the color of the snake. And with each move we check whether we are confronted with a tail, or with a bonus.
And in order to pass through the walls, we check if the next cell does not exist ahead, then we write to the snake coordinate array, if we write - 0 (the first position, the beginning of the line), or the last one. Depending on the direction of movement.
Example:
X = 100. Y = 200.
The snake moves the side of X ++, from zero position.
0,1,2,3..99, [if there is no cell and the direction does not change, then we write to array 0 along x]. And with Y, the same thing.

Now we will disassemble small modification.
In this modification, I made a bonus to escape from the snake. After some time, the bonus changes direction, and if it collides with a snake's tail, and not its head, it eats it. And she will eat until nothing of the snake remains, but she can be saved if she turns from the direction of the bonus.
There are two timers, at different speeds, which move the bonus and the snake. It would be possible to do everything in one timer, but then the speed would be the same, because You need to go through every cell, do not jump.
Still faced with the problem that when moving towards each other, the bonus and the snake, the first is not eaten. Due to the fact that they move independently. When the check occurs, the bonus has already moved to another cell.
I solved the problem. Delivered to a separate method, collision check code. Next, put this method to the bonus and to the snake.
What awaits you after the publication of the application
Since the application was originally planned without a rating, it was completely made in JavaScript, on the client side, that is, all the code is available to everyone and everyone who knows could send their number to the place of the earned result.
The main filters on the "important" sites were exposed. But the control of the incoming result was weak and the real result could have come, and such a “999999” could have come. Moreover, such a result came from schoolchildren who used hacking programs like “Charles,” as I happily told them in a personal, from their real accounts and from real ip-addresses.
Wrote a method that duplicated the result. In one parameter, a real, in another, encrypted result was transmitted by replacing the symbol with a key. And further, on the server both are compared and if something does not match, then - ban on account.
And yet, the server sends the generated key on the first access. The client must return it with the result. Without this key, the result will not be accepted and if everything matches, and everything passes the test, the result is written to the database, and a new key is generated, which is again given to the client. This is done in order to re-request with the result could not send, as is done in the program "Charles".
Here, the students already dropped out. Students who know JavaScript began to write in a personal.
After the introduction of additional checks, no one seems to be writing. Since only one attempt, and in which case the ban account VK.
And so, for good, all computational processes need to be transferred to the server, so that nothing can be replaced, but, that very high load is possible here.
They will also write the scammers offering to buy an application from you from 3000 rubles and up to $ 3000, which, if you google it, you can come across not very flattering reviews about them.
Schoolchildren, with different business proposals, become the admin of a group, or the admin of an application. They will also ask: “in which program did you create this game?”
Advisors who know how best to develop your application.
Trolls, where do without them.
findings
Financial side:
Domain - 200 rubles per year.
SSL Certificate (required) - the first year is free at startssl.com, and so, it costs from 1500 rubles. Self-signed certificate is not suitable.
VPS - 420rub for two months.
Spent on promotion - 0 rubles. True, I threw 100 rubles on advertising, purely to see what would happen. 25,000 hits. 12 transitions. 5 installations.
Advertising revenue - 76 rubles.
Profit : -544rub + elapsed time.
But the main thing is the enjoyment of the process.
If you develop an application aimed at profits, then only with the methods of retaining users, because with time they will decrease.
Monetization through advertising should be considered as an additional source of income, and not as a main source, if the daily number of users exceeds the thousandth threshold.
Therefore, there are so many applications that sell virtual goods for real money, because it is not profitable otherwise.
And finally, browser statistics:

And the daily time of user activity:

Screenshots with statistics from Vkontakte and Yandex-Metrics.
Thank you all for your attention.