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',
'thankyou' => 'd3/d3_googleanalytics/modules/controllers/d3_thankyou_googleanalytics',
),
'files' => array(
'd3_cfg_googleanalytics' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics.php',
'd3_cfg_googleanalytics_adwords' =>
'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_licence' =>
'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_licence.php',
'd3_cfg_googleanalytics_list' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_list.php',
'd3_cfg_googleanalytics_main' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_main.php',
'd3_cfg_googleanalytics_trustedstore' =>
'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_trustedstore.php',
'd3_cfg_googleanalyticslog' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalyticslog.php',
'd3_cfg_googleanalyticslog_list' =>
'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',
'files' => array(
'd3_cfg_googleanalytics' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics.php',
'd3_cfg_googleanalytics_adwords' => '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_licence' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_licence.php',
'd3_cfg_googleanalytics_list' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_list.php',
'd3_cfg_googleanalytics_main' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_main.php',
'd3_cfg_googleanalytics_trustedstore' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalytics_trustedstore.php',
'd3_cfg_googleanalyticslog' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalyticslog.php',
'd3_cfg_googleanalyticslog_list' => 'd3/d3_googleanalytics/controllers/admin/d3_cfg_googleanalyticslog_list.php',
'd3_google_articlelister' => 'd3/d3_googleanalytics/models/d3_google_articlelister.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',
'd3_googleanalytics_update' => 'd3/d3_googleanalytics/setup/d3_googleanalytics_update.php',
),
'templates' => array(
'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
/**
/**
* 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 © Data Development, Thomas Dartsch
* @author D³ Data Development - Daniel Seifert <ds@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_remarketing_articlelister
class d3_google_remarketing_articlelister extends d3_google_articlelister
{
public $sD3GARemarketingSKUField = 'oxartnum';
@ -98,7 +96,7 @@ class d3_google_remarketing_articlelister
*/
public function getSearchProdList($oView)
{
$oArticleList = $oView->getArticleList();
$oArticleList = parent::getSearchProdList($oView);
return $this->_getProductList($oArticleList);
}

View File

@ -1,20 +1,21 @@
<?php
/**
use D3\ModCfg\Application\Model\Configuration\d3_cfg_mod;
/**
* 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 © Data Development, Thomas Dartsch
* @author D³ Data Development - Daniel Seifert <support@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_trustedstore_articlelister
class d3_google_trustedstore_articlelister extends d3_google_articlelister
{
private $_sModId = 'd3_googleanalytics';
@ -96,7 +97,7 @@ class d3_google_trustedstore_articlelister
*/
public function getSearchProdList($oView)
{
$oArticleList = $oView->getArticleList();
$oArticleList = parent::getSearchProdList($oView);
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 Doctrine\DBAL\DBALException;
use OxidEsales\Eshop\Application\Controller\FrontendController;
use OxidEsales\Eshop\Application\Model\ArticleList;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
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());
}
$this->setECommerceParams();
if ($oSet->getValue('sD3GATSActive') && $oSet->getValue('sD3GATSShoppingActive')) {
$aInfos = $this->d3GATSGetProdInfos();
$oParentView->addTplParam('sD3GATSProdId', $this->d3GATSGetProdIdList($aInfos['aArtIdList']));
@ -109,6 +112,57 @@ class d3_oxcmp_utils_googleanalytics extends d3_oxcmp_utils_googleanalytics_pare
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
*/
@ -354,11 +408,11 @@ class d3_oxcmp_utils_googleanalytics extends d3_oxcmp_utils_googleanalytics_pare
{
startProfile(__METHOD__);
$oCurrentView = oxRegistry::getConfig()->getActiveView();
$oCurrentView = Registry::getConfig()->getActiveView();
$aArticleIds = array();
$sMethodName = 'get'.ucfirst($oCurrentView->getClassName())."ProdList";
$sMethodName = 'get'.ucfirst($oCurrentView->getClassKey())."ProdList";
$oArticleLister = oxNew('d3_google_trustedstore_articlelister');
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 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
*

View File

@ -301,6 +301,26 @@
</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%">
<tr>
<td class="edittext ext_edittext" align="left"><br>
@ -325,16 +345,6 @@
[{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>
<dl>
<dt>
<label for="blD3GAUseNetto">[{oxmultilang ident="D3_GOOGLEANALYTICS_ECOMMERCE_USENETTO"}]</label>

View File

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

View File

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