package Birdy::Stat::Stalin; # # , # , # # ######################################################## # ######################################################## # # !######### # # !########! ##! # !########! ### # !########## #### # ######### ##### ###### # !###! !####! ###### # ! ##### ######! # !####! ####### # ##### ####### # !####! #######! # ####!######## # ## ########## # ,######! !############# # ,#### ########################!####! # ,####' ##################!' ##### # ,####' ####### !####! # ####' ##### # ~## ##~ # # ######################################################## # ########################################################
// public enum Action { none, // install,// hit,// clickon_surfbutton,// clickon_volumebutton,// // open_surf,// open_feed,// open_popular,// open_dayDigest,// open_profile,// open_settings,// open_comment,// // / (/) registrationBegin_vk,//done registrationSignIn_vk,//done registrationSignUp_vk,//done registrationBegin_fb,//done registrationSignIn_fb,//done registrationSignUp_fb,//done registrationBegin_email,//done registrationComplete_email,//done // page_seen,// page_click,// (8 ) page_open,// ( ) page_read,// // share_fb,//done share_vk,//done share_sms,//done share_email,//done share_pocket,//done share_copyLink,//done share_saveImage,//done share_twitter,//done share_other,//done // like,//done dislike,//done favorite,//done addToCollection,//done // openPush,//done deliveredPush,//done //and so on }
public ClassEvent (Action action, Screen screen, ContentType contentType, String contentID, String abTest1, String abTest2, String description, int count) { this.abTest1 = abTest1; this.abTest2 = abTest2; //and so on this.contentType = contentType; this.contentID = contentID; this.time = System.currentTimeMillis()/1000; this.deviceID = SurfingbirdApplication.getInstance().getDeviceId(); this.deviceType = "ANDROID"; String loginToken = SurfingbirdApplication.getInstance().getSettings().getLoginToken(); this.userToken = loginToken==null?"":loginToken; this.clientVersion = SurfingbirdApplication.getInstance().getAppVersion(); } @Override public String toString() { JSONObject jsonObject= new JSONObject(); try { jsonObject.put("clientVersion", clientVersion); jsonObject.put("action", action.toString()); jsonObject.put("screen", screen); jsonObject.put("contentType", contentType); jsonObject.put("contentID", contentID); jsonObject.put("time", time); jsonObject.put("deviceID", deviceID); jsonObject.put("deviceType", deviceType); jsonObject.put("userToken", userToken); jsonObject.put("abTest1_id", abTest1); jsonObject.put("abTest1_value", abTest2); jsonObject.put("description", description); jsonObject.put("count", count); } catch (JSONException e) { AQUtility.debug("EVENTERROR",e.toString()); } return jsonObject.toString(); }
public void newEvent(ClassEvent.Action action,ClassEvent.Screen screen,ClassEvent.ContentType contentType,String contentId) { registerEvent(new ClassEvent(action,screen,contentType,contentId)); } public void newEvent(ClassEvent.Action action,ClassEvent.Screen screen,ClassEvent.ContentType contentType,String contentId,String abTest1,String abTest2,String description, int count) { registerEvent(new ClassEvent(action,screen,contentType,contentId,abTest1,abTest2,description,count)); } public void registerEvent(ClassEvent event) { Tracker t = getTracker( SurfingbirdApplication.TrackerName.GLOBAL_TRACKER); t.setScreenName(event.screen.toString()); Map<String, String> hits = new HitBuilders.EventBuilder() .setCategory("event") .setAction(event.action.toString()) .setLabel(event.action.toString()) .build(); t.send(hits); if (TextUtils.equals("",event.userToken) || TextUtils.equals("null",event.userToken)) { String eventsString = "["; eventsString+=event.toString(); eventsString+="]"; events.clear(); aq.ajax(UtilsApi.eventsCallBackBasic(this, "some_method", eventsString)); } else { events.add(event); if (events.size()>50) { sendEvents(); } } } public void sendEvents() { if (events.size()>0) { String eventsString = "["; for (ClassEvent event: events) { if (!eventsString.equals("[")) eventsString+=","; eventsString+=event.toString(); } eventsString+="]"; events.clear(); aq.ajax(UtilsApi.eventsCallBack(this, "nop", eventsString)); } }
SurfingbirdApplication.getInstance().newEvent(ClassEvent.Action.install, ClassEvent.Screen.none, ClassEvent.ContentType.none, ""); SurfingbirdApplication.getInstance().newEvent(ClassEvent.Action.openPush, ClassEvent.Screen.page_parsed, ClassEvent.ContentType.siteShort,shortUrl); SurfingbirdApplication.getInstance().newEvent(ClassEvent.Action.registrationBegin_email, ClassEvent.Screen.start, ClassEvent.ContentType.none, "");
// AFHTTPRequestOperationManager - (void) POST:(NSString *)path parameters:(NSMutableDictionary *)parameters success:(void (^__strong)(AFHTTPRequestOperation *__strong, __strong id))success failure:(void (^__strong)(AFHTTPRequestOperation *__strong, NSError *__strong))failure { SBEvents *events = [SBEventTracker sharedTracker].events; if (events.count > 0) { parameters[@"_events"] = [events jsonString]; [[SBEventTracker sharedTracker] clearEvents]; } [super POST:path parameters:parameters success:^(AFHTTPRequestOperation *operation, id json) { // } failure:^(AFHTTPRequestOperation *operation, NSError *error) { // }]; }
package Birdy::Stat::Stalin; use constant { SUCCESS => 'success', FAILURE => 'failure', UNKNOWN => 'unknown', CONTENT_TYPE_NONE => 'none', }; sub track_events { my $params = shift; return unless ref $params eq 'ARRAY'; return unless @$params; my ($s_events, $f_events, $u_events) = ([],[],[]); foreach (@$params) { my $event = __PACKAGE__->new($_); $event->parse; # given ($event->status) { when (SUCCESS) { push @$s_events, $event; } when (FAILURE) { push @$f_events, $event; } when (UNKNOWN) { push @$u_events, $event; } } } __PACKAGE__->_track_success_events($s_events); __PACKAGE__->_track_failure_events('failure', $f_events); __PACKAGE__->_track_failure_events('unknown', $u_events); } state $enums = { 'action' => [qw/ install hit open_surf open_feed open_popular open_dayDigest open_profile open_settings open_comment registrationBegin_email registrationComplete_email page_seen page_click page_open share_fb share_vk share_sms share_email share_pocket share_copyLink share_saveImage share_twitter share_other like dislike favorite addToCollection openPush deliveredPush openDayDigestFromLocalPush error page_read none /], 'screen' => [qw/ none start similar surf feed popular dayDigest profile settings page_parsed page_image siteTag actionBar actionBar_profile actionBar_page actionBar_channel profile_channel profile_add profile_like profile_favorite profile_collection /], 'deviceType' => ['IPAD', 'IPHONE', 'ANDROID'], 'contentType' => [CONTENT_TYPE_NONE, 'siteShort', 'userShort', 'siteTag'], }; state $fields = [ sort (keys %$enums, qw/time deviceID clientVersion userId userLogin contentID shortUrl count description/) ]; sub parse { my ($self) = @_; my $event_param = {}; { my $required = [keys %$enums]; my $optional = []; # # - , unless ( $self->_check_params($required) ) { $self->status(FAILURE); return; } # , # , # , , unless ( $self->_check_enum_params($required) ) { $self->status(UNKNOWN); return; } my $params = $self->_parse_params([@$required, @$optional]); $event_param = { %$params, %$event_param }; } { my $required = ['time', 'deviceID', 'clientVersion']; my $optional = ['userToken', 'count', 'description']; # contentID , contentType eq 'none' push @{ $event_param->{'contentType'} eq CONTENT_TYPE_NONE ? $optional : $required }, 'contentID'; # # - , unless ( $self->_check_params($required) ) { $self->status(FAILURE); return; } my $params = $self->_parse_params([@$required, @$optional]); $event_param = { # , (map { $_ => undef } @$optional), %$params, %$event_param, }; } $event_param->{'time'} = Birdy::TimeUtils::unix2date( $event_param->{'time'} ); $self->status(SUCCESS); $self->params($event_param); return; } # hashref sub _parse_params { my ($self, $params) = @_; $params = [] if ref $params ne 'ARRAY'; my $result = {}; foreach my $key (@$params) { my $value = $self->params->{$key}; next unless $value; $result->{$key} = $value; } return $result; }
Source: https://habr.com/ru/post/250517/
All Articles