1

I have something similar to twitter's feeds where we load it in real-time. How do i track how many people have seen a tweet? I am not talking about if you go to domain.com/post/32434 and that loads a status. I am talking about AJAX real-time query where one post is being loaded one after the other.

Will Google Analytics or Charbeat have anything that will help fulfill this need for me?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
ariel
  • 2,962
  • 7
  • 27
  • 31

1 Answers1

1

Why not managing your own counter in the database?

I don't really know your criteria, but let say you basically want to count how many times a given tweet was loaded.

Very quickly, I could think of this: The table:

CREATE TABLE tweets_loads(ID_TWEET INT NOT NULL, LOADS BIGINT NOT NULL DEFAULT 0, PRIMARY KEY `ID_TWEET`) ENGINE=InnoDB;

The query at each ajax request:

INSERT INTO tweets_loads (ID_TWEET, LOADS) VALUES (myTweetId, 1)
ON DUPLICATE KEY UPDATE LOADS = LOADS + 1;

(Assuming mysql)

Run it from php and that's it... Up to you then to check competition between inserts though, but in theory mysql should handle it just well...

Sebas
  • 21,192
  • 9
  • 55
  • 109
  • Whoa, can i? i wasn't aware of such a thing. HOw will i do that? – ariel Jun 01 '12 at 00:10
  • thanks Sebas. YOu mention that "count how many times a given tweet was loaded" that means that its going to insert a record for each time a user was shown that, right? – ariel Jun 01 '12 at 00:30
  • it is going to insert a record the first time and then increase the amount – Sebas Jun 01 '12 at 00:32
  • say there are 10,000 people live on the site and if it was loaded on the page i want to be able to track that 10,000 saw that tweet... – ariel Jun 01 '12 at 00:39
  • yeah, you will have a row for each tweet and the number of times it was "loaded", keeping increasing... You don't want to store the users who actually loaded it do you? It would cause much more overhead – Sebas Jun 01 '12 at 00:41
  • well if they go to say status.php?id=343 then i still would clock how many times it was loaded. But do you think with what we have we can track live viewers... like my example said say 10k people are live then the tracker should say when this tweet was loaded 10k people viewed it... something like that. – ariel Jun 01 '12 at 00:48
  • Yeah, it should be ok... The ajax is asynchronous, mysql will proceed the update statement as fast as it can but after a few ms, you will have the result :-) – Sebas Jun 01 '12 at 00:53
  • you're welcome, I Hope it works.. keep me posted, I'll be interested to know how it is going on! – Sebas Jun 01 '12 at 00:57