Skip to content
Browse files

Ecommerce meta first version

  • Loading branch information...
1 parent 9d11fd1 commit 46a3389168a7cb8e368d075a1b9e8d25a6c844c7 @eduardocereto eduardocereto committed Aug 16, 2012
Showing with 63 additions and 0 deletions.
  1. +63 −0 src/plugins/ecommerce_meta.js
View
63 src/plugins/ecommerce_meta.js
@@ -0,0 +1,63 @@
+/**
+ * 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]);
+

0 comments on commit 46a3389

Please sign in to comment.
Something went wrong with that request. Please try again.