You can write your own code and build it has a plugin with the behaviour gen_mod that ejabberd gives you.
A nice place to begin with is this blog/tutorial and follow to next part.
This should be enough but you will find more on the same blog.
After you get a little more comfortable with building your own module I suggest you take a look at the hooks set_presence_hook and unset_presence_hook
Just notice that set_presence_hook is activated every time a presence is set, not only on log in, you just have to work that around, if you can.
Long story short you will end up with something like the following
-module(mod_your_mod).
-behavior(gen_mod).
-include("ejabberd.hrl").
-export([start/2, stop/1, on_set/4, on_unset/4]).
start(Host, _Opts) ->
ejabberd_hooks:add(set_presence_hook, Host, ?MODULE, on_set, 50),
ejabberd_hooks:add(unset_presence_hook, Host, ?MODULE, on_unset, 50),
ok.
stop(Host) ->
ejabberd_hooks:delete(set_presence_hook, Host, ?MODULE, on_set, 50),
ejabberd_hooks:delete(unset_presence_hook, Host, ?MODULE, on_unset, 50),
ok.
on_set(User, Server, _Resource, _Packet) ->
<presence code>
on_unset(User, Server, _Resource, _Packet) ->
<offline code>
Hope this help