-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracking.module
193 lines (189 loc) · 5.19 KB
/
tracking.module
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
/**
* Implements hook_help().
*/
function tracking_help($path, $arg){
$out='';
switch ($path) {
case "help.page.tracking":
$controller = new \Drupal\tracking\Controller\TrackingController;
$out = $controller->helpPage();
}
return $out;
}
/**
* Handles callback from admin form when "delete all tracking records" button pushed.
* @param array $form
* @param \Drupal\Core\Form\FormStateInterface $form_state
*/
function tracking_admin_submit($form, \Drupal\Core\Form\FormStateInterface $form_state){
// call the delete function with no arguments.
try {
\Drupal\tracking\Reporting\Tracking::deleteTracking(array());
drupal_set_message('Deleted ALL Tracking Records', 'status');
}
catch(PDOException $e){
drupal_set_message('Tracking Records NOT Deleted', 'error');
}
}
/**
* Make the tables available to the views module ...
* Implements hook_views_data().
*/
function tracking_views_data() {
$data['tm_tracking'] = array(
'table'=>array(
'group' => t('Click and Impression Tracking'),
'provider' => 'Tracking Module',
'base' => array(
'field' => 'recid',
'title' => 'Click and Impression Tracking',
'help' => '',
'weight' => -10
),
'join' => array(
'users_field_data' => array(
// Primary key field in users to use in the join.
'left_field' => 'uid',
// Foreign key field in tm_tracking to use in the join.
'field' => 'user_id',
),
),
),
'recid' => array(
'title'=>'Identifier',
'help'=>'...',
'relationship' => array(
'base' => 'tm_tracking_log',
'base_field' => 'recid',
'id' => 'standard',
'label' => 'label',
),
),
'track_type'=>array(
'title'=>'Tracking Type',
'help'=>'The type of event that has been tracked (click or impression)',
'field'=>['id'=>'standard'],
'sort'=>['id'=>'standard'],
'filter'=>['id'=>'string'],
'argument'=>['id'=>'string'],
),
'source'=>array(
'title'=>'Source',
'help'=>'Where the event was originated',
'field'=>['id'=>'standard'],
'sort'=>['id'=>'standard'],
'filter'=>['id'=>'string'],
'argument'=>['id'=>'string'],
),
'campaign_id'=>array(
'title'=>'Campaign',
'help'=>'The campaign the event was associated with',
'field'=>['id'=>'standard'],
'sort'=>['id'=>'standard'],
'filter'=>['id'=>'string'],
'argument'=>['id'=>'string'],
),
'user_id'=>array(
'title'=>'UserID (uid)',
'help'=>'The UserID for the user being tracked',
/*'field'=>['id'=>'numeric'],
'sort'=>['id'=>'standard'],
'filter'=>['id'=>'numeric'],
'argument'=>['id'=>'numeric'],*/
'relationship' => array(
'base' => 'users_field_data',
'base_field' => 'uid',
'id' => 'standard',
'label' => 'label',
),
),
'timestamp'=>array(
'title'=>'Updated',
'help'=>'The time of last event for campaign',
'field'=>['id'=>'date'],
'sort'=>['id'=>'date'],
'filter'=>['id'=>'date'],
'argument'=>['id'=>'date'],
),
'destinationURL'=>array(
'title'=>'Destination URL',
'help'=>'For clicks, the URL that was clicked',
'field'=>['id'=>'standard'],
'sort'=>['id'=>'standard'],
'filter'=>['id'=>'string'],
'argument'=>['id'=>'string'],
),
'count'=>array(
'title'=>'Count',
'help'=>'The number of events that have been recorded',
'field'=>['id'=>'numeric'],
'sort'=>['id'=>'standard'],
'filter'=>['id'=>'numeric'],
'argument'=>['id'=>'numeric'],
),
);
$data['tm_tracking_log'] = array(
'table'=>array(
'group' => t('Click and Impression Tracking'),
'provider' => 'Tracking Module',
'join' => array(
'tm_tracking' => array(
// Primary key field in tm_tracking to use in the join.
'left_field' => 'recid',
// Foreign key field in tm_tracking_log to use in the join.
'field' => 'recid',
),
),
),
'lid' => array(
'title'=>'Identifier',
'help'=>'...',
),
'recid'=>array(
'title'=>'Rec ID',
'help'=>'RecID',
'field'=>['id'=>'numeric'],
'sort'=>['id'=>'standard'],
'filter'=>['id'=>'numeric'],
'argument'=>['id'=>'numeric'],
),
'timestamp'=>array(
'title'=>'Timestamp',
'help'=>'The time the event was recorded',
'field'=>['id'=>'date'],
'sort'=>['id'=>'date'],
'filter'=>['id'=>'date'],
'argument'=>['id'=>'date'],
),
'ipaddress'=>array(
'title'=>'IPAddress',
'help'=>'The IPAddress the event was called from',
'field'=>['id'=>'standard'],
'sort'=>['id'=>'standard'],
'filter'=>['id'=>'string'],
'argument'=>['id'=>'string'],
),
'hosttype'=>array(
'title'=>'Host',
'help'=>'Info about the users browser from headers',
'field'=>['id'=>'standard'],
'sort'=>['id'=>'standard'],
'filter'=>['id'=>'string'],
'argument'=>['id'=>'string'],
),
'email'=>array(
'title'=>'Email',
'help'=>'The tracked users email (if provided)',
'field'=>['id'=>'standard'],
'sort'=>['id'=>'standard'],
'filter'=>['id'=>'string'],
'argument'=>['id'=>'string'],
),
);
$data['users_field_data']['table']['join']['tm_tracking'] = array(
'left_field' => "user_id",
'field' => 'uid'
);
return $data;
}