Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 62 additions & 24 deletions examples/example_integration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,48 +24,51 @@ void printLog(Countly::LogLevel level, const string& msg) {
case Countly::LogLevel::FATAL:
lvl = "[FATAL]";
break;

default:
break;
}
cout<<lvl<<msg<<endl;

cout << lvl << msg << endl;
}



int main() {
cout<<"Sample App"<<endl;
cout << "Sample App" << endl;
Countly& ct = Countly::getInstance();
ct.alwaysUsePost(true);
ct.setDeviceID("test-device-id");

void (*logger_function)(Countly::LogLevel level, const std::string& message);
void (*logger_function)(Countly::LogLevel level, const std::string & message);
logger_function = printLog;
ct.setLogger(logger_function);
// OS, OS_version, device, resolution, carrier, app_version);
ct.SetMetrics("Windows 10", "10.22", "Mac", "800x600", "Carrier", "1.0");
ct.setCustomUserDetails({{"Account Type", "Basic"}, {"Employer", "Company4"}});
// Server and port
ct.Start("YOUR_APP_KEY", "https://try.count.ly", 443);
ct.start("8c1d653f8f474be24958b282d5e9b4c4209ee552", "https://master.count.ly", 443, true);
ct.SetMaxEventsPerMessage(10);
ct.SetMinUpdatePeriod(10);
ct.setUpdateInterval(15);
ct.setAutomaticSessionUpdateInterval(5);

bool flag = true;
while (flag) {
cout<<"Choose your option:"<<endl;
cout<<"1) Basic Event"<<endl;
cout<<"2) Event with count and sum"<<endl;
cout<<"3) Event with count, sum, duration"<<endl;
cout<<"4) Event with sum, count, duration and segmentation"<<endl;
cout<<"5) Update Session"<<endl;
cout<<"0) Exit"<<endl;
cout << "Choose your option:" << endl;
cout << "1) Basic Event" << endl;
cout << "2) Event with count and sum" << endl;
cout << "3) Event with count, sum, duration" << endl;
cout << "4) Event with sum, count, duration and segmentation" << endl;
cout << "5) Update Session" << endl;
cout << "6) Download remote config" << endl;
cout << "7) Send user detail to server" << endl;
cout << "8) Change device id with server merge" << endl;
cout << "9) Change device id without server merge" << endl;
cout << "10) Set user location" << endl;
cout << "0) Exit" << endl;
int a;
cin>>a;
cin >> a;
switch (a) {
case 1:
ct.RecordEvent("Basic Event", 123);
ct.RecordEvent("[CLY]_view", 123);
break;
case 2:
ct.RecordEvent("Event with count and sum", 644, 13.3);
Expand All @@ -77,24 +80,59 @@ int main() {
}
case 4: {
std::map<std::string, std::string> segmentation;
segmentation["height"] = "5.10";
ct.RecordEvent("Event with sum, count, duration and segmentation", segmentation, 1, 0, 10);
segmentation["name"] = "start and end";
ct.RecordEvent("Event with segmentation, count and sum", segmentation, 1, 0, 10);
break;
}
case 5:
ct.updateSession();
break;
case 6: {
ct.updateRemoteConfig();
break;
}
case 7: {
std::map<std::string, std::string> userdetail = {
{"name", "Full name"},
{"username", "username123"},
{"email", "useremail@email.com"},
{"phone", "222-222-222"},
{"phone", "222-222-222"},
{"picture", "http://webresizer.com/images2/bird1_after.jpg"},
{"gender", "M"},
{"byear", "1991"},
{"organization", "Organization"},
};

ct.getInstance().setUserDetails(userdetail);
}
break;
case 8:
ct.setDeviceID("new-device-id", true);
break;
case 9:
ct.setDeviceID("new-device-id", false);
break;
case 10: {
string countryCode = "us";
string city = "Houston";
string latitude = "29.634933";
string longitude = "-95.220255";
string ipAddress = "192.168.0.1";

ct.setLocation(countryCode, city, latitude + "," + longitude, ipAddress);
}
break;
case 0:
flag = false;
break;
default:
cout<<"Option not found!"<<endl;
cout << "Option not found!" << endl;
break;
}
}

//ct.updateSession();
ct.endSession();
ct.stop();

return 0;
}
}