Reputation: 561
I am building an e-commerce application, using NodeJS, ElasticSearch and MySQL.
I want to be able to track visitors, in order to determine which categories are popular, which products are most popular ( based on views and amount sold ) etc.
I plan on monitoring these things per Country.
The problem is that I do not know of any good ways to accomplish this. I am well aware of Google Analytics, but it only collects data. I can not integrate it into my application. ( I can't use the data from GA to show the user what's popular ). I looked for node.js packages that could do this sort of thing, but found none.
Because of this, I feel like I am left with only one option - create a system of my own for tracking popular items, categories etc. How would I go about doing that?
At first, I feel like I should create some new tables, one for popular products and one for popular categories. Then, on each click ( on a product or category ), I would add a new entry to the tables, and specify the country of the visitor.
For example, when some one clicks on a product, append this to the tables:
productID | countryOfClick
Another thing I could do is just add new columns to the products table. ( numberOfClicks, numberOfPurchases ) etc, but with this method I don't know how I would track which countries the clicks came from.
Is there a third way?
Am I completely missing the point?
Upvotes: 3
Views: 300
Reputation: 691
If your application is generating some log files (and for sure in production this will be the case i guess ), simply log the events that you are interested in some log files: e.g. 12:38:30 [USA] GET /products/item2344.
Then simply parse the log file with logstash (extracting the lines of interest) that it will insert in elastic-search. In elastic-search using kibana you can create aggregation grouping by country, product, counting the page more requested etc...
The advantage is that you are not slowing down your system when the user visit on the website because the log analysis and ingestion will be done asynchronously.
If you application is generating a log of log file, consider of having a retention of few hours for them.
Upvotes: 2