Merge branch 'ticket-GAnalytics' into develop
This commit is contained in:
commit
808a5a797b
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
@ -29,7 +29,7 @@ if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
class GAnalytics extends Module
|
||||
{
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
$this->name = 'ganalytics';
|
||||
@ -37,35 +37,36 @@ class GAnalytics extends Module
|
||||
$this->version = '1.3';
|
||||
$this->author = 'PrestaShop';
|
||||
$this->displayName = 'Google Analytics';
|
||||
|
||||
|
||||
parent::__construct();
|
||||
|
||||
|
||||
if ($this->id AND !Configuration::get('GANALYTICS_ID'))
|
||||
$this->warning = $this->l('You have not yet set your Google Analytics ID');
|
||||
$this->description = $this->l('Integrate Google Analytics script into your shop');
|
||||
$this->confirmUninstall = $this->l('Are you sure you want to delete your details ?');
|
||||
}
|
||||
|
||||
|
||||
function install()
|
||||
{
|
||||
if (!parent::install() OR !$this->registerHook('header') OR !$this->registerHook('orderConfirmation'))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function uninstall()
|
||||
{
|
||||
if (!Configuration::deleteByName('GANALYTICS_ID') OR !parent::uninstall())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
$output = '<h2>Google Analytics</h2>';
|
||||
if (Tools::isSubmit('submitGAnalytics') AND ($gai = Tools::getValue('ganalytics_id')))
|
||||
{
|
||||
Configuration::updateValue('GANALYTICS_ID', $gai);
|
||||
Configuration::updateValue('GANALYTICS_EC', Tools::getValue('ganalytics_ec'));
|
||||
$output .= '
|
||||
<div class="conf confirm">
|
||||
<img src="../img/admin/ok.gif" alt="" title="" />
|
||||
@ -86,10 +87,15 @@ class GAnalytics extends Module
|
||||
<input type="text" name="ganalytics_id" value="'.Tools::safeOutput(Tools::getValue('ganalytics_id', Configuration::get('GANALYTICS_ID'))).'" />
|
||||
<p class="clear">'.$this->l('Example:').' UA-1234567-1</p>
|
||||
</div>
|
||||
<label>'.$this->l('Enhanced Commerce ?').'</label>
|
||||
<div class="margin-form">
|
||||
<input type="radio" name="ganalytics_ec" value="1" '.(((int)Configuration::get('GANALYTICS_EC')==1)?"checked":"").'/> '.$this->l('ec.js').'
|
||||
<input type="radio" name="ganalytics_ec" value="0" '.(((int)Configuration::get('GANALYTICS_EC')==0)?"checked":"").' /> '.$this->l('ecommerce.js').'
|
||||
</div>
|
||||
<center><input type="submit" name="submitGAnalytics" value="'.$this->l('Update ID').'" class="button" /></center>
|
||||
</fieldset>
|
||||
</form>';
|
||||
|
||||
|
||||
$output .= '
|
||||
<fieldset class="space">
|
||||
<legend><img src="../img/admin/unknown.gif" alt="" class="middle" />'.$this->l('Help').'</legend>
|
||||
@ -145,18 +151,18 @@ class GAnalytics extends Module
|
||||
<li>'.$this->l('Save this new goal').'</li>
|
||||
</ol>
|
||||
</fieldset>';
|
||||
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
function hookHeader($params)
|
||||
{
|
||||
global $smarty, $cookie;
|
||||
|
||||
|
||||
// hookOrderConfirmation() already send the sats bypass this step
|
||||
if (strpos($_SERVER['REQUEST_URI'], __PS_BASE_URI__.'order-confirmation.php') === 0)
|
||||
return '';
|
||||
|
||||
|
||||
// Otherwise, create Google Analytics stats
|
||||
$ganalytics_id = Configuration::get('GANALYTICS_ID');
|
||||
$multilang = (Language::countActiveLanguages() > 1);
|
||||
@ -166,9 +172,10 @@ class GAnalytics extends Module
|
||||
$smarty->assign('ganalytics_id', $ganalytics_id);
|
||||
$smarty->assign('pageTrack', $pageTrack);
|
||||
$smarty->assign('isOrder', false);
|
||||
$smarty->assign('isEC', (int)Configuration::get('GANALYTICS_EC'));
|
||||
return $this->display(__FILE__, 'header.tpl');
|
||||
}
|
||||
|
||||
|
||||
function hookFooter($params)
|
||||
{
|
||||
// for retrocompatibility
|
||||
@ -182,10 +189,10 @@ class GAnalytics extends Module
|
||||
global $smarty;
|
||||
// Setting parameters
|
||||
$parameters = Configuration::getMultiple(array('PS_LANG_DEFAULT'));
|
||||
|
||||
|
||||
$order = $params['objOrder'];
|
||||
if (Validate::isLoadedObject($order))
|
||||
{
|
||||
{
|
||||
$deliveryAddress = new Address(intval($order->id_address_delivery));
|
||||
|
||||
$conversion_rate = 1;
|
||||
@ -212,10 +219,10 @@ class GAnalytics extends Module
|
||||
foreach ($products AS $product)
|
||||
{
|
||||
$category = Db::getInstance()->getRow('
|
||||
SELECT name FROM `'._DB_PREFIX_.'category_lang` , '._DB_PREFIX_.'product
|
||||
WHERE `id_product` = '.intval($product['product_id']).' AND `id_category_default` = `id_category`
|
||||
SELECT name FROM `'._DB_PREFIX_.'category_lang` , '._DB_PREFIX_.'product
|
||||
WHERE `id_product` = '.intval($product['product_id']).' AND `id_category_default` = `id_category`
|
||||
AND `id_lang` = '.intval($parameters['PS_LANG_DEFAULT']));
|
||||
|
||||
|
||||
$items[] = array(
|
||||
'OrderId' => intval($order->id), // order ID - required
|
||||
'SKU' => addslashes($product['product_id']), // SKU/code - required
|
||||
@ -229,6 +236,7 @@ class GAnalytics extends Module
|
||||
$smarty->assign('items', $items);
|
||||
$smarty->assign('trans', $trans);
|
||||
// $smarty->assign('ganalytics_id', $ganalytics_id);
|
||||
$smarty->assign('isEC', (int)Configuration::get('GANALYTICS_EC'));
|
||||
$smarty->assign('isOrder', true);
|
||||
return $this->display(__FILE__, 'header.tpl');
|
||||
}
|
||||
|
@ -1,30 +1,52 @@
|
||||
<script type="text/javascript">
|
||||
{if $isOrder eq true}
|
||||
{if $isEC == 0}
|
||||
ga('require', 'ecommerce', 'ecommerce.js');
|
||||
|
||||
ga('require', 'ecommerce', 'ecommerce.js');
|
||||
ga('ecommerce:addTransaction', {
|
||||
'id': '{$trans.id}', // Transaction ID. Required
|
||||
'affiliation': '{$trans.store}', // Affiliation or store name.
|
||||
'revenue': '{$trans.total}', // Grand Total.
|
||||
'shipping': '{$trans.shipping}', // Shipping.
|
||||
'tax': '{$trans.tax}' // Tax.
|
||||
});
|
||||
|
||||
ga('ecommerce:addTransaction', {
|
||||
'id': '{$trans.id}', // Transaction ID. Required
|
||||
'affiliation': '{$trans.store}', // Affiliation or store name.
|
||||
'revenue': '{$trans.total}', // Grand Total.
|
||||
'shipping': '{$trans.shipping}', // Shipping.
|
||||
'tax': '{$trans.tax}' // Tax.
|
||||
});
|
||||
{foreach from=$items item=item}
|
||||
ga('ecommerce:addItem', {
|
||||
'id': '{$item.OrderId}', // Transaction ID. Required.
|
||||
'name': '{$item.Product}', // Product name. Required.
|
||||
'sku': 'DD23444', // SKU/code.
|
||||
'category': '{$item.Category}', // Category or variation.
|
||||
'price': '{$item.Price}', // Unit price.
|
||||
'quantity': '{$item.Quantity}' // Quantity.
|
||||
});
|
||||
{/foreach}
|
||||
|
||||
{foreach from=$items item=item}
|
||||
ga('ecommerce:addItem', {
|
||||
'id': '{$item.OrderId}', // Transaction ID. Required.
|
||||
'name': '{$item.Product}', // Product name. Required.
|
||||
'sku': 'DD23444', // SKU/code.
|
||||
'category': '{$item.Category}', // Category or variation.
|
||||
'price': '{$item.Price}', // Unit price.
|
||||
'quantity': '{$item.Quantity}' // Quantity.
|
||||
});
|
||||
{/foreach}
|
||||
ga('ecommerce:send');
|
||||
ga('ecommerce:clear');
|
||||
{else}
|
||||
ga('require', 'ec');
|
||||
|
||||
ga('ecommerce:send');
|
||||
ga('ecommerce:clear');
|
||||
{foreach from=$items item=item}
|
||||
ga('ec:addProduct', { // Provide product details in an productFieldObject.
|
||||
'id': '{$item.SKU}', // Product ID (string).
|
||||
'name': '{$item.Product}', // Product name (string).
|
||||
'category': '{$item.Category}', // Product category (string).
|
||||
'price': '{$item.Price}', // Product price (currency).
|
||||
'quantity': {$item.Quantity} // Product quantity (number).
|
||||
});
|
||||
{/foreach}
|
||||
|
||||
ga('ec:setAction', 'purchase', { // Transaction details are provided in an actionFieldObject.
|
||||
'id': '{$trans.id}', // (Required) Transaction id (string).
|
||||
'affiliation': '{$trans.store}', // Affiliation (string).
|
||||
'revenue': '{$trans.total}', // Revenue (currency).
|
||||
'tax': '{$trans.tax}', // Tax (currency).
|
||||
'shipping': '{$trans.shipping}', // Shipping (currency).
|
||||
});
|
||||
|
||||
ga('send', 'pageview');
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
</script>
|
||||
|
@ -76,6 +76,7 @@
|
||||
<link href="{$css_dir}ie9.css" rel="stylesheet" type="text/css" media="screen" />
|
||||
<![endif]-->
|
||||
|
||||
{assign var='isEC' value=Configuration::get('GANALYTICS_EC')}
|
||||
{if $cookie->id_lang == 2}
|
||||
{literal}
|
||||
<script>
|
||||
@ -144,7 +145,10 @@
|
||||
{/literal}{/if}
|
||||
{/if}{literal}
|
||||
|
||||
ga('send', 'pageview');
|
||||
{/literal}{if isset($page_name) && (($page_name == 'order-confirmation' && $isEC==0) || $page_name != 'order-confirmation')}{literal}
|
||||
// send pageview via header.tpl du module GA si isEC=1 and $page_name == 'order-confirmation'
|
||||
ga('send', 'pageview');
|
||||
{/literal}{/if}{literal}
|
||||
|
||||
function onStepComplete(stepNumber, option, redirect, form) {
|
||||
ga('ec:setAction', 'checkout_option', {
|
||||
|
Loading…
Reference in New Issue
Block a user