1- #include < thread >
1+ #include " countly.hpp "
22#include < chrono>
3- #include < random>
43#include < iostream>
5- #include " countly.hpp"
4+ #include < random>
5+ #include < thread>
6+ #ifdef _WIN32
7+ #include < Windows.h>
8+ #else
9+ #include < unistd.h>
10+ #endif
611
712using namespace std ;
813
9- void printLog (Countly::LogLevel level, const string& msg) {
10- string lvl = " [DEBUG]" ;
11- switch (level) {
12- case Countly::LogLevel::DEBUG:
13- lvl = " [Debug]" ;
14- break ;
15- case Countly::LogLevel::INFO:
16- lvl = " [INFO]" ;
17- break ;
18- case Countly::LogLevel::WARNING:
19- lvl = " [WARNING]" ;
20- break ;
21- case Countly::LogLevel::ERROR:
22- lvl = " [ERROR]" ;
23- break ;
24- case Countly::LogLevel::FATAL:
25- lvl = " [FATAL]" ;
26- break ;
14+ void printLog (Countly::LogLevel level, const string &msg) {
15+ string lvl = " [DEBUG]" ;
16+ switch (level) {
17+ case Countly::LogLevel::DEBUG:
18+ lvl = " [Debug]" ;
19+ break ;
20+ case Countly::LogLevel::INFO:
21+ lvl = " [INFO]" ;
22+ break ;
23+ case Countly::LogLevel::WARNING:
24+ lvl = " [WARNING]" ;
25+ break ;
26+ case Countly::LogLevel::FATAL:
27+ lvl = " [FATAL]" ;
28+ break ;
29+ default :
30+ lvl = " [ERROR]" ;
31+ break ;
32+ }
2733
28- default :
29- break ;
30- }
31-
32- cout << lvl << msg << endl;
34+ cout << lvl << msg << endl;
3335}
3436
37+ int main () {
38+ cout << " Sample App" << endl;
39+ Countly &ct = Countly::getInstance ();
40+ ct.alwaysUsePost (true );
41+ ct.setDeviceID (" test-device-id" );
3542
43+ ct.setLogger (printLog);
44+ // OS, OS_version, device, resolution, carrier, app_version);
45+ ct.SetMetrics (" Windows 10" , " 10.22" , " Mac" , " 800x600" , " Carrier" , " 1.0" );
46+ // Server and port
47+ ct.start (" YOUR_APP_KEY" , " https://try.count.ly" , 443 , true );
48+ ct.SetMaxEventsPerMessage (10 );
49+ ct.setAutomaticSessionUpdateInterval (5 );
3650
37- int main () {
38- cout << " Sample App" << endl;
39- Countly& ct = Countly::getInstance ();
40- ct.alwaysUsePost (true );
41- ct.setDeviceID (" test-device-id" );
51+ bool flag = true ;
52+ while (flag) {
53+ cout << " Choose your option:" << endl;
54+ cout << " 1) Basic Event" << endl;
55+ cout << " 2) Event with count and sum" << endl;
56+ cout << " 3) Event with count, sum, duration" << endl;
57+ cout << " 4) Event with sum, count, duration and segmentation" << endl;
58+ cout << " 5) Update Session" << endl;
59+ cout << " 6) Download remote config" << endl;
60+ cout << " 7) Send user detail to server" << endl;
61+ cout << " 8) Change device id with server merge" << endl;
62+ cout << " 9) Change device id without server merge" << endl;
63+ cout << " 10) Set user location" << endl;
64+ cout << " 11) Record a view" << endl;
65+ cout << " 0) Exit" << endl;
66+ int a;
67+ cin >> a;
68+ switch (a) {
69+ case 1 :
70+ ct.RecordEvent (" [CLY]_view" , 123 );
71+ break ;
72+ case 2 :
73+ ct.RecordEvent (" Event with count and sum" , 644 , 13.3 );
74+ break ;
75+ case 3 : {
76+ Countly::Event event (" Event with sum, count, duration" , 1 , 10 , 60.5 );
77+ ct.addEvent (event);
78+ break ;
79+ }
80+ case 4 : {
81+ std::map<std::string, std::string> segmentation;
82+ segmentation[" name" ] = " start and end" ;
83+ ct.RecordEvent (" Event with segmentation, count and sum" , segmentation, 1 , 0 , 10 );
84+ break ;
85+ }
86+ case 5 :
87+ ct.updateSession ();
88+ break ;
89+ case 6 : {
90+ ct.updateRemoteConfig ();
91+ break ;
92+ }
93+ case 7 : {
94+ std::map<std::string, std::string> userdetail = {
95+ {
" name" ,
" Full name" }, {
" username" ,
" username123" }, {
" email" ,
" [email protected] " }, {
" phone" ,
" 222-222-222" }, {
" phone" ,
" 222-222-222" }, {
" picture" ,
" http://webresizer.com/images2/bird1_after.jpg" }, {
" gender" ,
" M" }, {
" byear" ,
" 1991" }, {
" organization" ,
" Organization" },
96+ };
97+
98+ ct.getInstance ().setUserDetails (userdetail);
99+ } break ;
100+ case 8 :
101+ ct.setDeviceID (" new-device-id" , true );
102+ break ;
103+ case 9 :
104+ ct.setDeviceID (" new-device-id" , false );
105+ break ;
106+ case 10 : {
107+ string countryCode = " us" ;
108+ string city = " Houston" ;
109+ string latitude = " 29.634933" ;
110+ string longitude = " -95.220255" ;
111+ string ipAddress = " 192.168.0.1" ;
112+
113+ ct.setLocation (countryCode, city, latitude + " ," + longitude, ipAddress);
114+ } break ;
42115
43- ct.setLogger (printLog);
44- // OS, OS_version, device, resolution, carrier, app_version);
45- ct.SetMetrics (" Windows 10" , " 10.22" , " Mac" , " 800x600" , " Carrier" , " 1.0" );
46- // Server and port
47- ct.start (" APP_KEY" , " https://try.count.ly" , 443 , true );
48- ct.SetMaxEventsPerMessage (10 );
49- ct.setAutomaticSessionUpdateInterval (5 );
116+ case 11 : {
117+ std::map<std::string, std::string> segmentation = {
118+ {" platform" , " ubuntu" },
119+ {" time" , " 60" },
120+ };
50121
51- bool flag = true ;
52- while (flag) {
53- cout << " Choose your option:" << endl;
54- cout << " 1) Basic Event" << endl;
55- cout << " 2) Event with count and sum" << endl;
56- cout << " 3) Event with count, sum, duration" << endl;
57- cout << " 4) Event with sum, count, duration and segmentation" << endl;
58- cout << " 5) Update Session" << endl;
59- cout << " 6) Download remote config" << endl;
60- cout << " 7) Send user detail to server" << endl;
61- cout << " 8) Change device id with server merge" << endl;
62- cout << " 9) Change device id without server merge" << endl;
63- cout << " 10) Set user location" << endl;
64- cout << " 0) Exit" << endl;
65- int a;
66- cin >> a;
67- switch (a) {
68- case 1 :
69- ct.RecordEvent (" [CLY]_view" , 123 );
70- break ;
71- case 2 :
72- ct.RecordEvent (" Event with count and sum" , 644 , 13.3 );
73- break ;
74- case 3 : {
75- Countly::Event event (" Event with sum, count, duration" , 1 , 10 , 60.5 );
76- ct.addEvent (event);
77- break ;
78- }
79- case 4 : {
80- std::map<std::string, std::string> segmentation;
81- segmentation[" name" ] = " start and end" ;
82- ct.RecordEvent (" Event with segmentation, count and sum" , segmentation, 1 , 0 , 10 );
83- break ;
84- }
85- case 5 :
86- ct.updateSession ();
87- break ;
88- case 6 : {
89- ct.updateRemoteConfig ();
90- break ;
91- }
92- case 7 : {
93- std::map<std::string, std::string> userdetail = {
94- {" name" , " Full name" },
95- {" username" , " username123" },
96- 97- {" phone" , " 222-222-222" },
98- {" phone" , " 222-222-222" },
99- {" picture" , " http://webresizer.com/images2/bird1_after.jpg" },
100- {" gender" , " M" },
101- {" byear" , " 1991" },
102- {" organization" , " Organization" },
103- };
122+ // Open a view
123+ std::string viewID = ct.views ().openView (" Main view" , segmentation);
104124
105- ct.getInstance ().setUserDetails (userdetail);
106- }
107- break ;
108- case 8 :
109- ct.setDeviceID (" new-device-id" , true );
110- break ;
111- case 9 :
112- ct.setDeviceID (" new-device-id" , false );
113- break ;
114- case 10 : {
115- string countryCode = " us" ;
116- string city = " Houston" ;
117- string latitude = " 29.634933" ;
118- string longitude = " -95.220255" ;
119- string ipAddress = " 192.168.0.1" ;
125+ Sleep (2000 ); // two seconds
120126
121- ct. setLocation (countryCode, city, latitude + " , " + longitude, ipAddress);
122- }
123- break ;
124- case 0 :
125- flag = false ;
126- break ;
127- default :
128- cout << " Option not found!" << endl;
129- break ;
130- }
131- }
127+ // Close an opened view
128+ ct. views (). closeViewWithID (viewID);
129+ } break ;
130+ case 0 :
131+ flag = false ;
132+ break ;
133+ default :
134+ cout << " Option not found!" << endl;
135+ break ;
136+ }
137+ }
132138
133- ct.stop ();
139+ ct.stop ();
134140
135- return 0 ;
141+ return 0 ;
136142}
0 commit comments