add basic ecommerce features

# Conflicts:
#	copy_this/modules/d3/d3_googleanalytics/metadata.php
This commit is contained in:
Daniel Seifert 2019-09-19 23:03:37 +02:00 committed by Daniel Seifert
parent e25e1d3a34
commit f315d14622
8 changed files with 353 additions and 75 deletions

View File

@ -55,26 +55,20 @@ $aModule = array(
'oxutilsview' => 'd3/d3_googleanalytics/modules/core/d3_oxutilsview_googleanalytics', 'oxutilsview' => 'd3/d3_googleanalytics/modules/core/d3_oxutilsview_googleanalytics',
'thankyou' => 'd3/d3_googleanalytics/modules/controllers/d3_thankyou_googleanalytics', 'thankyou' => 'd3/d3_googleanalytics/modules/controllers/d3_thankyou_googleanalytics',
), ),
'files' => array( 'files' => array(
'd3_cfg_googleanalytics' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics.php', 'd3_cfg_googleanalytics' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics.php',
'd3_cfg_googleanalytics_adwords' => 'd3_cfg_googleanalytics_adwords' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_adwords.php',
'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_adwords.php', 'd3_cfg_googleanalytics_campaigns' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_campaigns.php',
'd3_cfg_googleanalytics_campaigns' => 'd3_cfg_googleanalytics_licence' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_licence.php',
'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_campaigns.php', 'd3_cfg_googleanalytics_list' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_list.php',
'd3_cfg_googleanalytics_licence' => 'd3_cfg_googleanalytics_main' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_main.php',
'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_licence.php', 'd3_cfg_googleanalytics_trustedstore' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_trustedstore.php',
'd3_cfg_googleanalytics_list' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_list.php', 'd3_cfg_googleanalyticslog' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalyticslog.php',
'd3_cfg_googleanalytics_main' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_main.php', 'd3_cfg_googleanalyticslog_list' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalyticslog_list.php',
'd3_cfg_googleanalytics_trustedstore' => 'd3_google_articlelister' => 'd3/d3_googleanalytics/models/d3_google_articlelister.php',
'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_trustedstore.php', 'd3_google_remarketing_articlelister' => 'd3/d3_googleanalytics/models/d3_google_remarketing_articlelister.php',
'd3_cfg_googleanalyticslog' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalyticslog.php', 'd3_google_trustedstore_articlelister' => 'd3/d3_googleanalytics/models/d3_google_trustedstore_articlelister.php',
'd3_cfg_googleanalyticslog_list' => 'd3_googleanalytics_update' => 'd3/d3_googleanalytics/setup/d3_googleanalytics_update.php',
'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalyticslog_list.php',
'd3_googleanalytics_update' => 'd3/d3_googleanalytics/setup/d3_googleanalytics_update.php',
'd3_google_remarketing_articlelister' =>
'd3/d3_googleanalytics/models/d3_google_remarketing_articlelister.php',
'd3_google_trustedstore_articlelister' =>
'd3/d3_googleanalytics/models/d3_google_trustedstore_articlelister.php',
), ),
'templates' => array( 'templates' => array(
'd3ga_universal_adwordscode.tpl' => 'd3/d3_googleanalytics/views/tpl/widget/inc/d3ga_universal_adwordscode.tpl', 'd3ga_universal_adwordscode.tpl' => 'd3/d3_googleanalytics/views/tpl/widget/inc/d3ga_universal_adwordscode.tpl',

View File

@ -0,0 +1,201 @@
<?php
use OxidEsales\Eshop\Application\Model\ArticleList;
/**
* This Software is the property of Data Development and is protected
* by copyright law - it is NOT Freeware.
* Any unauthorized use of this software without a valid license
* is a violation of the license agreement and will be prosecuted by
* civil and criminal law.
* http://www.shopmodule.com
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link http://www.oxidmodule.com
*/
class d3_google_articlelister
{
public $aStartListMethodNames = array(
'getArticleList',
'getTopArticleList',
'getNewestArticles',
'getFirstArticle',
'getCatOfferArticleList',
);
/**
* @param start $oView
*
* @return array
*/
public function getStartProdList($oView)
{
/** @var oxArticleList $oArticleList */
$oArticleList = oxNew('oxarticlelist');
if (is_array($this->aStartListMethodNames) && count($this->aStartListMethodNames)) {
foreach ($this->aStartListMethodNames as $sListName) {
/** @var oxArticleList $oList */
$mList = call_user_func(array($oView, $sListName));
if ($mList instanceof oxArticleList) {
if ($mList->count()) {
foreach ($mList->getArray() as $sID => $oArticle) {
$oArticleList->offsetSet($sID, $oArticle);
}
}
}
}
}
return $this->_getProductList($oArticleList);
}
/**
* @param details $oView
*
* @return array
*/
public function getDetailsProdList($oView)
{
$aArticleList = array();
$aArticleList[] = $oView->getProduct();
return $this->_getProductList($aArticleList);
}
/**
* @param oxwArticleDetails $oView
*
* @return array
*/
public function getOxwarticledetailsProdList($oView)
{
$aArticleList = array();
$aArticleList[] = $oView->getProduct();
return $this->_getProductList($aArticleList);
}
/**
* @param alist $oView
*
* @return array
*/
public function getAlistProdList($oView)
{
return $oView->getArticleList();
}
/**
* @param search $oView
*
* @return ArticleList
*/
public function getSearchProdList($oView)
{
return $oView->getArticleList();
}
/**
* @param vendorlist $oView
*
* @return array
*/
public function getVendorlistProdList($oView)
{
return $oView->getArticleList();
}
/**
* @param manufacturerlist $oView
*
* @return array
*/
public function getManufacturerlistProdList($oView)
{
return $oView->getArticleList();
}
/**
* @param basket $oView
*
* @return array
*/
public function getBasketProdList($oView)
{
$aArticleList = $oView->getBasketArticles();
return $this->_getProductList($aArticleList);
}
/**
* @param order $oView
*
* @return array
*/
public function getOrderProdList($oView)
{
$aArticleList = $oView->getBasketArticles();
return $this->_getProductList($aArticleList);
}
/**
* @param compare $oView
*
* @return array
*/
public function getCompareProdList($oView)
{
$aArticleList = $oView->getCompArtList();
return $this->_getProductList($aArticleList);
}
/**
* don't change method name, it was dynamically generated
* @param account_noticelist $oView
*
* @return array
*/
public function getAccount_noticelistProdList($oView)
{
$aArticleList = $oView->getNoticeProductList();
return $this->_getProductList($aArticleList);
}
/**
* don't change method name, it was dynamically generated
* @param account_wishlist $oView
*
* @return array
*/
public function getAccount_wishlistProdList($oView)
{
$aArticleList = $oView->getWishProductList();
return $this->_getProductList($aArticleList);
}
/**
* @param $aArticleList
*
* @return array
*/
protected function _getProductList($aArticleList)
{
$aArticleIds = array();
$dPrice = 0;
/** @var oxarticle $oArticle */
if (isset($aArticleList)) {
foreach ($aArticleList as $oArticle) {
$aArticleIds[] = $oArticle->getFieldData($this->sD3GARemarketingSKUField);
if ($this->blD3GARemarketingUseBrutto) {
$dPrice += $oArticle->getPrice()->getBruttoPrice();
} else {
$dPrice += $oArticle->getPrice()->getNettoPrice();
}
}
}
return array('aArtIdList' => $aArticleIds, 'dPrice' => $dPrice);
}
}

View File

@ -1,20 +1,18 @@
<?php <?php
/** /**
* This Software is the property of Data Development and is protected * This Software is the property of Data Development and is protected
* by copyright law - it is NOT Freeware. * by copyright law - it is NOT Freeware.
*
* Any unauthorized use of this software without a valid license * Any unauthorized use of this software without a valid license
* is a violation of the license agreement and will be prosecuted by * is a violation of the license agreement and will be prosecuted by
* civil and criminal law. * civil and criminal law.
*
* http://www.shopmodule.com * http://www.shopmodule.com
* *
* @copyright © Data Development, Thomas Dartsch * @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D³ Data Development - Daniel Seifert <ds@shopmodule.com> * @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link http://www.oxidmodule.com * @link http://www.oxidmodule.com
*/ */
class d3_google_remarketing_articlelister class d3_google_remarketing_articlelister extends d3_google_articlelister
{ {
public $sD3GARemarketingSKUField = 'oxartnum'; public $sD3GARemarketingSKUField = 'oxartnum';
@ -98,7 +96,7 @@ class d3_google_remarketing_articlelister
*/ */
public function getSearchProdList($oView) public function getSearchProdList($oView)
{ {
$oArticleList = $oView->getArticleList(); $oArticleList = parent::getSearchProdList($oView);
return $this->_getProductList($oArticleList); return $this->_getProductList($oArticleList);
} }

View File

@ -1,20 +1,21 @@
<?php <?php
/**
use D3\ModCfg\Application\Model\Configuration\d3_cfg_mod;
/**
* This Software is the property of Data Development and is protected * This Software is the property of Data Development and is protected
* by copyright law - it is NOT Freeware. * by copyright law - it is NOT Freeware.
*
* Any unauthorized use of this software without a valid license * Any unauthorized use of this software without a valid license
* is a violation of the license agreement and will be prosecuted by * is a violation of the license agreement and will be prosecuted by
* civil and criminal law. * civil and criminal law.
*
* http://www.shopmodule.com * http://www.shopmodule.com
* *
* @copyright © Data Development, Thomas Dartsch * @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D³ Data Development - Daniel Seifert <support@shopmodule.com> * @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link http://www.oxidmodule.com * @link http://www.oxidmodule.com
*/ */
class d3_google_trustedstore_articlelister class d3_google_trustedstore_articlelister extends d3_google_articlelister
{ {
private $_sModId = 'd3_googleanalytics'; private $_sModId = 'd3_googleanalytics';
@ -96,7 +97,7 @@ class d3_google_trustedstore_articlelister
*/ */
public function getSearchProdList($oView) public function getSearchProdList($oView)
{ {
$oArticleList = $oView->getArticleList(); $oArticleList = parent::getSearchProdList($oView);
return $this->_getProductList($oArticleList); return $this->_getProductList($oArticleList);
} }

View File

@ -5,6 +5,7 @@ use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception;
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException; use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
use OxidEsales\Eshop\Application\Controller\FrontendController; use OxidEsales\Eshop\Application\Controller\FrontendController;
use OxidEsales\Eshop\Application\Model\ArticleList;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException; use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException; use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Exception\StandardException; use OxidEsales\Eshop\Core\Exception\StandardException;
@ -89,6 +90,8 @@ class d3_oxcmp_utils_googleanalytics extends d3_oxcmp_utils_googleanalytics_pare
$oParentView->addTplParam('sD3CurrentGTSLang', $this->d3GetGTSLang()); $oParentView->addTplParam('sD3CurrentGTSLang', $this->d3GetGTSLang());
} }
$this->setECommerceParams();
if ($oSet->getValue('sD3GATSActive') && $oSet->getValue('sD3GATSShoppingActive')) { if ($oSet->getValue('sD3GATSActive') && $oSet->getValue('sD3GATSShoppingActive')) {
$aInfos = $this->d3GATSGetProdInfos(); $aInfos = $this->d3GATSGetProdInfos();
$oParentView->addTplParam('sD3GATSProdId', $this->d3GATSGetProdIdList($aInfos['aArtIdList'])); $oParentView->addTplParam('sD3GATSProdId', $this->d3GATSGetProdIdList($aInfos['aArtIdList']));
@ -109,6 +112,57 @@ class d3_oxcmp_utils_googleanalytics extends d3_oxcmp_utils_googleanalytics_pare
return $ret; return $ret;
} }
/**
* @throws DBALException
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
*/
public function setECommerceParams()
{
/** @var $oParentView FrontendController */
$oParentView = $this->getParent();
$oSet = d3_cfg_mod::get($this->_d3getModId());
if ($oSet->getValue('blD3GASendECommerce')) {
$oParentView->addTplParam('blIsImpressionViewList', false);
if ($this->isImpressionViewList()) {
$oParentView->addTplParam('blIsImpressionViewList', true);
$oParentView->addTplParam('aD3GAProdInfos', $this->d3GAGetProdInfos());
$oParentView->addTplParam('sImpressionListType', $this->d3GAGetImpressionListType());
}
}
}
public function isImpressionViewList()
{
// ToDo: has to be completed
$impressionViews = ['search', 'start', 'alist', 'vendorlist', 'manufacturerlist'];
$oCurrentView = Registry::getConfig()->getActiveView();
return in_array($oCurrentView->getClassKey(), $impressionViews);
}
public function d3GAGetImpressionListType()
{
$oCurrentView = Registry::getConfig()->getActiveView();
// ToDo: has to be completed
switch ($oCurrentView->getClassKey()) {
case 'search':
return "Search Results";
case 'start':
return "Start Page Results";
case 'alist':
return "Category Results";
case 'vendorlist':
return "Vendor List Results";
case 'manufacturerlist':
return "Manufacturer List Results";
}
}
/** /**
* @return string * @return string
*/ */
@ -354,11 +408,11 @@ class d3_oxcmp_utils_googleanalytics extends d3_oxcmp_utils_googleanalytics_pare
{ {
startProfile(__METHOD__); startProfile(__METHOD__);
$oCurrentView = oxRegistry::getConfig()->getActiveView(); $oCurrentView = Registry::getConfig()->getActiveView();
$aArticleIds = array(); $aArticleIds = array();
$sMethodName = 'get'.ucfirst($oCurrentView->getClassName())."ProdList"; $sMethodName = 'get'.ucfirst($oCurrentView->getClassKey())."ProdList";
$oArticleLister = oxNew('d3_google_trustedstore_articlelister'); $oArticleLister = oxNew('d3_google_trustedstore_articlelister');
if (method_exists($oArticleLister, $sMethodName)) { if (method_exists($oArticleLister, $sMethodName)) {
@ -371,6 +425,30 @@ class d3_oxcmp_utils_googleanalytics extends d3_oxcmp_utils_googleanalytics_pare
return array('aArtIdList' => $aArticleIds); return array('aArtIdList' => $aArticleIds);
} }
/**
* @return ArticleList
*/
public function d3GAGetProdInfos()
{
startProfile(__METHOD__);
$oCurrentView = Registry::getConfig()->getActiveView();
$aArticleIds = array();
$sMethodName = 'get'.ucfirst($oCurrentView->getClassKey())."ProdList";
$oArticleLister = oxNew('d3_google_articlelister');
if (method_exists($oArticleLister, $sMethodName)) {
stopProfile(__METHOD__);
return call_user_func(array($oArticleLister, $sMethodName), $oCurrentView);
}
stopProfile(__METHOD__);
return array('aArtIdList' => $aArticleIds);
}
/** /**
* @param array $aArticleIds * @param array $aArticleIds
* *

View File

@ -301,6 +301,26 @@
</div> </div>
</div> </div>
<div class="groupExp">
<div class="">
<a class="rc" onclick="_groupExp(this); return false;" href="#">
<span style="font-weight: bold;">
[{oxmultilang ident="D3_GOOGLEANALYTICS_ECOMMERCE"}]
</span>
</a>
<dl>
<dt>
<label for="blD3GASendECommerce">[{oxmultilang ident="D3_GOOGLEANALYTICS_ECOMMERCE_SENDDATA"}]</label>
</dt>
<dd>
<input type="hidden" name="value[blD3GASendECommerce]" value="0">
<input id="blD3GASendECommerce" class="edittext ext_edittext" type="checkbox" value="1" [{if $edit->getValue('blD3GASendECommerce')}]checked[{/if}] name="value[blD3GASendECommerce]">
[{oxinputhelp ident="D3_GOOGLEANALYTICS_ECOMMERCE_SENDDATA_DESC"}]
</dd>
</dl>
</div>
</div>
<table width="100%"> <table width="100%">
<tr> <tr>
<td class="edittext ext_edittext" align="left"><br> <td class="edittext ext_edittext" align="left"><br>
@ -325,16 +345,6 @@
[{oxmultilang ident="D3_GOOGLEANALYTICS_ECOMMERCE"}] [{oxmultilang ident="D3_GOOGLEANALYTICS_ECOMMERCE"}]
</span> </span>
</a> </a>
<dl>
<dt>
<label for="blD3GASendECommerce">[{oxmultilang ident="D3_GOOGLEANALYTICS_ECOMMERCE_SENDDATA"}]</label>
</dt>
<dd>
<input type="hidden" name="value[blD3GASendECommerce]" value="0">
<input id="blD3GASendECommerce" class="edittext ext_edittext" type="checkbox" value="1" [{if $edit->getValue('blD3GASendECommerce')}]checked[{/if}] name="value[blD3GASendECommerce]">
[{oxinputhelp ident="D3_GOOGLEANALYTICS_ECOMMERCE_SENDDATA_DESC"}]
</dd>
</dl>
<dl> <dl>
<dt> <dt>
<label for="blD3GAUseNetto">[{oxmultilang ident="D3_GOOGLEANALYTICS_ECOMMERCE_USENETTO"}]</label> <label for="blD3GAUseNetto">[{oxmultilang ident="D3_GOOGLEANALYTICS_ECOMMERCE_USENETTO"}]</label>

View File

@ -4,8 +4,8 @@
[{if $oD3GASettings->getValue('blD3GAUseOptOut')}] [{if $oD3GASettings->getValue('blD3GAUseOptOut')}]
[{block name="d3ga_optoutscript"}] [{block name="d3ga_optoutscript"}]
<script type="text/javascript"> <script type="text/javascript">
let gaProperty = '[{$oD3GASettings->getValue('sD3GAId')}]'; var gaProperty = '[{$oD3GASettings->getValue('sD3GAId')}]';
let disableStr = 'ga-disable-' + gaProperty; var disableStr = 'ga-disable-' + gaProperty;
if (document.cookie.indexOf(disableStr + '=true') > -1) { if (document.cookie.indexOf(disableStr + '=true') > -1) {
window[disableStr] = true; window[disableStr] = true;
} }

View File

@ -33,33 +33,29 @@ gtag('event', 'purchase', {
] ]
}); });
[{* https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce *}] [{if $blIsImpressionViewList}]
gtag('event', 'view_item_list', { [{* https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce *}]
"items": [ gtag('event', 'view_item_list', {
{ "items": [
"id": "P12345", [{foreach from=$aD3GAProdInfos name="itemlist" item="item"}]
"name": "Android Warhol T-Shirt", [{assign var="oPrice" value=$item->getPrice()}]
"list_name": "Search Results", [{assign var="oManufacturer" value=$item->getManufacturer()}]
"brand": "Google", [{assign var="oCategory" value=$item->getCategory()}]
"category": "Apparel/T-Shirts", {
"variant": "Black", "id": "[{$item->getFieldData('oxartnum')}]",
"list_position": 1, "name": "[{$item->getFieldData('oxtitle')}]",
"quantity": 2, "list_name": "[{$sImpressionListType}]",
"price": 2 "brand": "[{if $oManufacturer}][{$oManufacturer->getTitle()}][{/if}]",
}, "category": "[{if $oCategory}][{$oCategory->getTitle()}][{/if}]",
{ "variant": "",
"id": "P67890", "list_position": [{$smarty.foreach.itemlist.iteration}],
"name": "Flame challenge TShirt", "quantity": 1,
"list_name": "Search Results", "price": [{$oPrice->getPrice()}]
"brand": "MyBrand", },
"category": "Apparel/T-Shirts", [{/foreach}]
"variant": "Red", ]
"list_position": 2, });
"quantity": 1, [{/if}]
"price": 3
}
]
});
[{* https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce *}] [{* https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce *}]
gtag('event', 'view_item', { gtag('event', 'view_item', {