Himalayan-Academy / Siva-Siva-App

Code Repository for the Siva Siva Mobile App
11 stars 3 forks source link

Add Tracking of User Interactions with App #105

Open Brahmanathaswami opened 6 years ago

Brahmanathaswami commented 6 years ago

Possibly the simplest thing for now is: post items from the journal back to the server?

We probably want to store this in a dbase. What to use?

What to track:

soapdog commented 6 years ago

Just pushed this feature to the nightly branch. We need to decide where/when to record data.

Brahmanathaswami commented 6 years ago

@soapdog

I made the following changes/updates

1) to item table i added an enum column "cached_on_disk" as we need this in the app later and I had added it manually. We use this column to fetch photos form the local repository. later we can use it for other media that has been downloaded values are "true" or "false" without this my handlers for "updateLocalCached" fail. 2) fixed spelling of script from "dump_jnanan.sh" to "dump_jnanam. sh" ends with "m" 3) added another arg to the mysqldump -udevhap... because it would not run from a cron unless the user was declared. 4) added cron... tested works, runs daily at midnight every day 5) downloaded fresh copy to app, deleted old one.. everything working! Add transcript to AudioDetails view... awesome! 6) started adding tracking entries in the different modules/scripts

Brahmanathaswami commented 6 years ago

Add this command on lin 161 of behavior_InitSivaSivaProject

put the seconds into pData["action_timestamp"] tracking_RecordActivity "SivaSivaApp","init/launch", pData send "tracking_UploadData" to stack "model_SivaSivaTracking" in 3 seconds

We give time for the app to load the portal and then send the data.

i really think we need to do two change to the noomenclature

1) if the destination of the data in param "pType" is column "action" (which is what I am seeing in the analytics table" then can we please name that param "pAction" add make the local tracking.sqllite column a match?

2) I really think we should have a timestamp as "the seconds" (not a date) for the action, as a separate column. I added this to the analytics table on the server "action_timestamp" BIGIN Can we fix the local database and scripts to support this? just take pData["action_timestamp"] and pass it to the local table and have the API pass it to analytics.action_timestamp

Brahmanathaswami commented 6 years ago

Never mind on the time stamp. you are passing the stamp from the date created field on the database, but thit is also set to auto fill with timestamp ( I think) but ic an verify the entries are matching the time stamp in the local tracking.sqllite dbase.

FYI two things will break the up load

"gems/realm":3;

or

"navigation/goContent":"card \"audio\" of stack "\surprise\""

Both the above break the API's insert... I thought an unquoted integer was value json , because it is not quoted when the array converte do JSON, but the API does not like it.

soapdog commented 6 years ago

Swami, you're talking about two different topics in this issue. The dump_jnanam.sh is not related to tracking, anything related to that belongs somewhere else.

Both the SQLite database and the MySQL database have timestamp columns. They are autofilled, which happens in the case you do not set them yourself. Our PHP API server uses the timestamp from the SQLite database for the timestamp of the MySQL database.

Below is the schema of the SQLite database showing the timestamp field and a sample of entries. sqliteschema

Below is the schema of the MySQL database wiki hindu org _ localhost _ jnanam _ analytics _ phpmyadmin 4 0 10 1 - nightly 2017-09-04 14 18 41

Below is the PHP Code that inserts the data:

$app->post("/sivasiva/tracking/:uuid", function($uuid) use ($app, $log) {
    try {
        $request = $app->request();
        $body = $request->getBody();
        $input = json_decode($body, true);
        $res = Array();
        foreach ($input as $item) {
            $data = json_decode($item["data"], true);
            $data["module"] = $item["module"];
            $record = ORM::for_table("analytics")->create();
            $record->set("uuid", $uuid);
            $record->set("action", $item["type"]);
            $record->set("origin", "Siva Siva App");
            $record->set("date_created", $item["date"]);
            $record->set("data", json_encode($data));
            array_push($res, $record->save());
        }
        send_response(Array(
            "status" => "uploaded",
            "result" => $res,
            "msg" => "Saved"
        ));
    } catch (Exception $e) {
        $app->response()->status(400);
        $app->response()->header('X-Status-Reason', $e->getMessage());

        info("ERROR: " . $e->getMessage());

        send_response(Array(
            "status" => "error",
            "msg" => $e->getMessage(),
            "trace" => $e->getTraceAsString()
        ));

    }
});