Skip to content

Commit

Permalink
Merge pull request #7 from maze-consulting/feature/KSCU-48-orderconf-…
Browse files Browse the repository at this point in the history
…cleanup

KSCU-48: brings previous refactor commit into sitegen, plus removal o…
  • Loading branch information
aidrian-maze authored Mar 30, 2023
2 parents 2c87b81 + 946d504 commit b3aafd5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 395 deletions.
14 changes: 10 additions & 4 deletions cartridges/int_klaviyo/cartridge/controllers/Klaviyo.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ var r = require("*/cartridge/scripts/util/Response");
/* API Includes */
var ISML = require('dw/template/ISML');

var klaviyoUtils = require('*/cartridge/scripts/klaviyo/utils');
var viewedProductData = require('*/cartridge/scripts/klaviyo/eventData/viewedProduct');
var viewedCategoryData = require('*/cartridge/scripts/klaviyo/eventData/viewedCategory');
var searchedSiteData = require('*/cartridge/scripts/klaviyo/eventData/searchedSite');

/**
* Controller that sends the necessary data required for klaviyo to track user events
* such as checkout, order confirmation, searching etc and renders the renders the klaviyoTag isml file
Expand All @@ -21,27 +26,28 @@ var Event = function () {

if(dw.system.Site.getCurrent().getCustomPreferenceValue('klaviyo_enabled')){

var klaviyoUtils = require('*/cartridge/scripts/utils/klaviyo/klaviyoUtils');
var exchangeID = klaviyoUtils.getKlaviyoExchangeID();
var dataObj, serviceCallResult, action, parms;

if (exchangeID) {
action = request.httpParameterMap.action.stringValue;
parms = request.httpParameterMap.parms.stringValue;

var foo = 'bar';

switch(action) {
case klaviyoUtils.EVENT_NAMES.viewedProduct :
dataObj = klaviyoUtils.viewedProductData(parms); // parms: product ID
dataObj = viewedProductData.getData(parms); // parms: product ID
break;
case klaviyoUtils.EVENT_NAMES.viewedCategory :
dataObj = klaviyoUtils.viewedCategoryData(parms); // parms: category ID
dataObj = viewedCategoryData.getData(parms); // parms: category ID
break;
case klaviyoUtils.EVENT_NAMES.searchedSite :
// TODO: add Show-Ajax append? test to be sure when this happens... if its just on paging, do we want to track that?
// TODO: what about search-suggestion flyout? probably not supportable
// TODO: be sure to check for 0 result searches, filtering on both search results and PLPs, re-sorts, etc and get clarity on requirements
parms = parms.split('|');
dataObj = klaviyoUtils.searchedSiteData(parms[0], parms[1]); // parms: search phrase, result count
dataObj = searchedSiteData.getData(parms[0], parms[1]); // parms: search phrase, result count
break;
}
serviceCallResult = klaviyoUtils.trackEvent(exchangeID, dataObj, action);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<isscript>
var klaviyoUtils = require('*/cartridge/scripts/utils/klaviyo/klaviyoUtils.js');
var klaviyoUtils = require('*/cartridge/scripts/klaviyo/utils');
</isscript>
<!--- TEMPLATENAME: klaviyoTag.isml --->
<isif condition="${dw.system.Site.getCurrent().getCustomPreferenceValue('klaviyo_enabled')}">
Expand All @@ -13,14 +13,15 @@
<isset name="klAction" value="${klaviyoUtils.EVENT_NAMES.viewedProduct}" scope="page" />
<isset name="klParms" value="${pdict.Product.ID}" scope="page" />
<iselse>
<isif condition="${request.httpParameterMap.cgid.stringValue != ''}">
<isif condition="${request.httpParameterMap.cgid.stringValue}">
<isset name="klAction" value="${klaviyoUtils.EVENT_NAMES.viewedCategory}" scope="page" />
<isset name="klParms" value="${request.httpParameterMap.cgid.stringValue}" scope="page" />
<iselse>
<isset name="klAction" value="${klaviyoUtils.EVENT_NAMES.searchedSite}" scope="page" />
<isset name="klParms" value="${request.httpParameterMap.q.stringValue + '|' + pdict.ProductSearchResult.count}" scope="page" />
</isif>
</isif>
xxx ${klAction} ${request.httpParameterMap.cgid.stringValue} xxx
<isinclude url="${URLUtils.url('Klaviyo-Event', 'action', klAction, 'parms', klParms)}" />
</isif>
<isif condition="${pdict.klid}">
Expand Down
Loading

0 comments on commit b3aafd5

Please sign in to comment.