updated script with analytics stuff