/
ecommerce_meta.js
executable file
·63 lines (60 loc) · 1.68 KB
/
ecommerce_meta.js
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
/**
* GAS - Google Analytics on Steroids
*
* Ecommerce Meta
*
* Copyright 2011, Cardinal Path and Direct Performance
* Licensed under the GPLv3 license.
*
* @author Eduardo Cereto <eduardocereto@gmail.com>
*/
function _gasMetaEcommerce() {
var i, meta,
f_trans = 0,
f_item = 0,
metas = document.getElementsByTagName('meta');
for (i = 0; i < metas.length; i++) {
if (metas[i].name === 'ga_trans') {
// Fire transaction
meta = metas[i].content.split('*');
if (meta.length < 3) {
// 3 is the minimum for transaction
break;
}
while (meta.length < 8) {
meta.push('');
}
_gas.push(['_addTrans',
meta[0],
meta[1],
meta[2],
meta[3],
meta[4],
meta[5],
meta[6],
meta[7]
]);
f_trans++;
}
else if (metas[i].name === 'ga_item') {
// Fire item
meta = metas[i].content.split('*');
if (meta.length === 6) {
_gas.push(['_addItem',
meta[0],
meta[1],
meta[2],
meta[3],
meta[4],
meta[5]
]);
f_item++;
}
}
}
if (f_trans > 0 && f_item > 0) {
_gas.push(['_trackTrans']);
//_gas.push(['_clearTrans']);
}
}
_gas.push(['_addHook', '_gasMetaEcommerce', _gasMetaEcommerce]);