refactor js
add segment tracking