forked from snowplow/snowplow-cpp-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
85 lines (66 loc) · 2.08 KB
/
Copy pathmain.cpp
File metadata and controls
85 lines (66 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <string>
#include <time.h>
#include "../src/tracker.hpp"
using snowplow::ClientSession;
using snowplow::Emitter;
using snowplow::Subject;
using snowplow::Tracker;
using std::cout;
using std::endl;
using std::string;
void usage(char *program_name) {
cout << "Usage: " << program_name << " [COLLECTOR_URI]" << endl;
}
int main(int argc, char **argv) {
if (argc != 2) {
usage(argv[0]);
return 1;
}
// Create Tracker Variables
string uri = argv[1];
string db_name = "demo.db";
Emitter emitter(uri, Emitter::Method::POST, Emitter::Protocol::HTTP, 52000, 52000, 500, db_name);
Subject subject;
subject.set_user_id("a-user-id");
subject.set_screen_resolution(1920, 1080);
subject.set_viewport(1080, 1080);
subject.set_color_depth(32);
subject.set_timezone("GMT");
subject.set_language("EN");
subject.set_useragent("Mozilla/5.0");
ClientSession client_session(db_name, 5000, 5000);
string platform = "mob";
string app_id = "app-id";
string name_space = "namespace";
bool base64 = false;
bool desktop_context = true;
// Create Tracker
Tracker *t = Tracker::init(emitter, &subject, &client_session, &platform, &app_id, &name_space, &base64, &desktop_context);
time_t start, end;
time(&start);
for (int i = 0; i < 2000; i++) {
Tracker::TimingEvent te("timing-cat", "timing-var", 123);
Tracker::ScreenViewEvent sve;
string name = "Screen ID - 5asd56";
sve.name = &name;
Tracker::StructuredEvent se("shop", "add-to-basket");
string property = "pcs";
double value = 25.6;
se.property = &property;
se.value = &value;
t->track_timing(te);
t->track_screen_view(sve);
t->track_struct_event(se);
}
time(&end);
double diff = difftime(end, start);
printf("It took me %f seconds to build and store 6000 events.\n", diff);
// Flush and close
t->flush();
Tracker::close();
time(&end);
diff = difftime(end, start);
printf("It took me %f seconds to send 6000 events.\n", diff);
return 0;
}