Add Error handling to trackEvent