This repository has been archived by the owner on Mar 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
216 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["es2015"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 13 additions & 15 deletions
28
app/Resources/views/themes/ezplatform/line/bundle_card.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "ezplatform.com", | ||
"version": "2.3.0", | ||
"author": "eZ Systems", | ||
"homepage": "ez.no", | ||
"scripts": { | ||
"test": "mocha --compilers js:babel-core/register ./test/*.spec.js" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-core": "^6.26.3", | ||
"babel-preset-es2015": "^6.24.1", | ||
"chai": "^4.2.0", | ||
"chai-dom": "^1.8.1", | ||
"jsdom": "^13.0.0", | ||
"mocha": "^5.2.0", | ||
"sinon": "^7.1.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const expect = require('chai').expect, | ||
{ JSDOM } = require("jsdom"), | ||
GoogleAnalyticsService = require('../web/assets/js/GoogleAnalyticsService'); | ||
|
||
describe('GoogleAnalytics', () => { | ||
describe('GoogleAnalyticsService', () => { | ||
let gaService, | ||
document; | ||
|
||
const template = '/html/gaTemplate.html', | ||
gaDataAttr = 'data-ga-action', | ||
gaCategoryAttr = 'data-ga-category', | ||
gaLabelAttr = 'data-ga-label'; | ||
|
||
beforeEach(() => { | ||
gaService = new GoogleAnalyticsService(); | ||
|
||
return JSDOM.fromFile(__dirname + template) | ||
.then(dom => { | ||
return document = dom.window.document; | ||
}) | ||
.catch(error => { | ||
console.log(error); | ||
}); | ||
}); | ||
|
||
it('should return instance of GoogleAnalyticsService', () => { | ||
expect(gaService).to.be.instanceOf(GoogleAnalyticsService); | ||
}); | ||
|
||
it ('should find selectors with data attribute data-ga-action', () => { | ||
return expect(document.querySelectorAll(`[${gaDataAttr}]`)).not.to.have.lengthOf(0); | ||
}); | ||
|
||
it ('should return value for each data-ga-action attribute', () => { | ||
let selectors = document.querySelectorAll(`[${gaDataAttr}]`); | ||
selectors.forEach(selector => { | ||
return expect(selector.getAttribute(gaDataAttr)).not.to.have.lengthOf(0); | ||
}); | ||
}); | ||
|
||
it ('should return true if body has data-ga-category attribute', () => { | ||
return expect(document.body.hasAttribute(gaCategoryAttr)).to.be.true; | ||
}); | ||
|
||
it ('should return value for data-ga-category attribute', () => { | ||
return expect(document.querySelector(`[${gaCategoryAttr}]`).getAttribute(gaCategoryAttr)).not.to.have.lengthOf(0); | ||
}); | ||
|
||
it ('should return Google Analytics Label if data-ga-label attribute exists', () => { | ||
let selectors = document.querySelectorAll(`[${gaLabelAttr}]`); | ||
selectors.forEach(selector => { | ||
return expect(selector.getAttribute(gaLabelAttr)).not.to.have.lengthOf(0); | ||
}); | ||
}); | ||
|
||
it ('should set event listener for every selector with data-ga-action attribute', () => { | ||
// @TODO; | ||
}); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head></head> | ||
<body data-ga-category="dwadwa"> | ||
<p data-ga-action="action1">Action name</p> | ||
<p data-ga-action="action2">Action name</p> | ||
<p data-ga-label="label">Label</p> | ||
<p data-ga-label="label2">Label</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class GoogleAnalyticsItem { | ||
|
||
constructor(type = 'event', category, action, label = null, transport = {}) { | ||
this.type = type; | ||
this.category = category; | ||
this.action = action; | ||
this.label = label; | ||
this.transport = transport; | ||
} | ||
} | ||
|
||
module.exports = GoogleAnalyticsItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
class GoogleAnalyticsService { | ||
|
||
constructor () { | ||
this.gaDataAttr = 'data-ga-action'; | ||
this.gaCategoryAttr = 'data-ga-category'; | ||
this.gaLabelAttr = 'data-ga-label'; | ||
} | ||
|
||
init() { | ||
const gaSelectors = document.querySelectorAll(`[${this.gaDataAttr}]`); | ||
|
||
if (gaSelectors.length > 0) { | ||
gaSelectors.forEach(selector => { | ||
selector.addEventListener('click', (event) => { | ||
let action = event.currentTarget.getAttribute('data-ga-action'), | ||
category = this.getGACategory(); | ||
|
||
this.sendGARequest(new GoogleAnalyticsItem('event', category , action, this.getGALabel(selector))); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
getGACategory() { | ||
const body = document.body; | ||
|
||
return body.hasAttribute(this.gaCategoryAttr) ? Utils.capitalize(body.getAttribute(this.gaCategoryAttr)) : null; | ||
} | ||
|
||
getGALabel(selector) { | ||
if (typeof selector !== "undefined") { | ||
return selector.hasAttribute(this.gaLabelAttr) ? selector.getAttribute(this.gaLabelAttr) : null; | ||
} | ||
} | ||
|
||
sendGARequest(gaItem) { | ||
if (gaItem instanceof GoogleAnalyticsItem) { | ||
ga( | ||
'send', | ||
gaItem.type, | ||
gaItem.category, | ||
gaItem.action, | ||
gaItem.label = typeof gaItem.label !== "undefined" ? gaItem.label : delete gaItem.label, | ||
gaItem.transport = typeof gaItem.transport !== "undefined" ? gaItem.transport : delete gaItem.transport | ||
); | ||
} | ||
} | ||
} | ||
|
||
module.exports = GoogleAnalyticsService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Utils { | ||
|
||
static capitalize (string) { | ||
return string.charAt(0).toUpperCase() + string.slice(1); | ||
} | ||
} |
Oops, something went wrong.