analytics.php
2.22 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
<?php
class ControllerGeekodevAnalytics extends Controller {
public function index() {
header('Content-type: text/javascript');
?>
function gkdEctTrack(action, pid, desc) {
var async = action == 'remove' ? false : true;
$.ajax({
url: 'index.php?route=geekodev/analytics/getTrackData',
type: 'post', dataType: 'json', cache: false, async: async,
data: {pid: pid, action: action},
success: function(res) {
if (typeof res[0] !== 'undefined') {
gkaLayer.push({
'event': action,
'ecommerce': {
'add': {
'products': res
}
}
});
/*
ga('ec:addProduct', res[0]);
ga('ec:setAction', action);
ga('send', 'event', $(document).find('title').text(), desc, res[0].name);
*/
}
}
});
}
function gkdEctTrackCheckout(step, desc) {
if (typeof jQuery != 'undefined') {
$.ajax({
url: 'index.php?route=geekodev/analytics/getTrackData',
type: 'post', dataType: 'json', cache: false,
data: {cart:1},
success: function(res) {
if (typeof res[0] !== 'undefined') {
gkaLayer.push({
'event': 'checkout',
'ecommerce': {
'checkout': {
'actionField': {'step': step},
'products': res
}
}
});
}
/*
for(var i=0; i<res.length; i++) {
if (typeof res[i] !== 'undefined') {
ga('ec:addProduct', res[i]);
}
}
ga('ec:setAction', 'checkout', {'step':step, 'option':desc});
ga('send', 'pageview');
*/
}
});
}
}
if (typeof jQuery != 'undefined') {
$(document).delegate('#button-confirm', 'click', function(){
gkdEctTrackCheckout(3, 'Checkout confirm');
});
}
<?php
exit;
}
public function getTrackData($asArray = false) {
$json = array();
$this->load->model('tool/seo_package');
$json = $this->model_tool_seo_package->getTrackData();
header('Content-Type: application/json');
echo json_encode($json);
}
}