Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
randohinn committed May 13, 2017
1 parent 056b43a commit 5cda3e0
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
7 changes: 7 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2017 Rando Hinn

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Voog-GACommerce
[![Voog badge](https://img.shields.io/badge/Voog-voog.com-blue.svg)](https://voog.com)

Voog-GACommerce is a simple drop-in solution for tracking [Voog](https://voog.com) E-Commerce purchases in the [Google Analytics](https://analytics.google.com) Ecommerce section.

## Usage

You need to have GA set up on your site beforehand.

* Download the script and upload it to your components folder in the editor. In `Settings` -> `Site`, add this inside the already present GA script tag under External stats, after `ga('send', 'pageview');`

```
var s = document.createElement( 'script' );
s.setAttribute( 'src', '/javascripts/Voog-GACommerce.js' );
document.body.appendChild( s );
```

This makes sure, that GACommerce loads after GA has been set up and exists to be used.

* Start buying, the script will now automatically detect checkouts and send data to GA. Processing might take some time.

**Since Voog doesn't have categories in the Store feature itself, all items will be sent with category 'Product'.**

## Contributing

Feel free to Fork and PR this repo, aswell as submit any issues.
32 changes: 32 additions & 0 deletions Voog-GACommerce.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
ga('require', 'ecommerce'); // We need Google Analytics to actually know what we want to do. Thus, give us Ecommerce!

(function () {
$(document).on('voog:shoppingcart:show', (event) => {
if(event.detail.view === "review") {
let shoppingcart = Voog.ShoppingCart.getShoppingCartData();
ga('ecommerce:clear'); // Existing unsent data from before? Make it dissapear
ga('ecommerce:addTransaction', {
'id': shoppingcart.uuid, // Transaction ID.
'affiliation': VoogEcommerce.storeInfo.company_name, // Affiliation or store name.
'revenue': shoppingcart.total_amount.toString(), // Grand Total.
'shipping': shoppingcart.shipping_subtotal_amount.toString(), // Shipping.
'tax': shoppingcart.items_tax_amount.toString() // Tax.
});
shoppingcart.items.forEach(function(item) {
ga('ecommerce:addItem', {
'id': shoppingcart.uuid,
'name': item.name,
'sku': item.product.name, // Yes, this is not a SKU, but the review view doesn't seem to have 'em...
'category': 'Product',
'price': item.product.price.toString(),
'quantity': item.quantity.toString(),
'currency': VoogEcommerce.storeInfo.currency
});
}, this);
}
});

$(document).on('voog:shoppingcart:choosepaymentmethod', () => {
ga('ecommerce:send');
});
})();

0 comments on commit 5cda3e0

Please sign in to comment.