Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hmpo-templates

Package Overview
Dependencies
Maintainers
3
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hmpo-templates - npm Package Compare versions

Comparing version 2.7.0 to 2.8.0

.editorconfig

6

package.json
{
"name": "hmpo-templates",
"version": "2.7.0",
"version": "2.8.0",
"description": "Page layouts and partials for Node.js with ExpressJS frontend applications",
"main": "index.js",
"scripts": {
"test": "mocha ./test --recursive"
"test": "eslint . && mocha ./test --recursive"
},

@@ -25,3 +25,3 @@ "repository": {

"chai": "^4.1.2",
"cheerio": "^1.0.0-rc.2",
"eslint": "^4.15.0",
"hogan.js": "^3.0.2",

@@ -28,0 +28,0 @@ "mocha": "^4.0.1"

@@ -61,2 +61,4 @@ # hmpo-templates

+ analytics
+ gtm
+ gtm-noscript
+ back-link

@@ -94,1 +96,49 @@ + back

Use with [hmpo-template-mixins](https://github.com/UKHomeOffice/passports-template-mixins) for form inputs and view formatters. When used with [hmpo-form-wizard](https://github.com/UKHomeOffice/passports-form-wizard) you'll get a validation summary appearing at the top of your page when a form error occurs.
## Google Analytics Classic
To enable Google Analytics tracking expose a GA ID as `res.locals['ga-id']`.
Page views and form validation error events will be sent to GA.
Events contained in the array `res.locals.gaevents` will be fired on page view, for instance:
```
res.locals.gaevents = [
{
gaCategory: 'Category',
gaAction: 'Action',
gaLabel: 'Label',
gaValue: 42
}
];
```
## Google Tag Manager
To enable Google Tag Manager expose GTM settings as:
```
res.locals.gtm = {
id: 'GT-XXXXXX',
preview: 'env-1',
auth: 'abcdefg'
};
```
For production environments only an ID is required.
Page views and form validation error events will be sent to GTM.
Events contained in the array `res.locals.gaevents` will be fired on page view, for instance:
```
res.locals.gaevents = [
{
gaEvent: 'My Event', // defaults to 'Custom Event'
gaCategory: 'Category',
gaAction: 'Action',
gaLabel: 'Label',
gaValue: 42
}
];
```
_Note: Enabling Google Tag Manager will disable Google Analytics Classic_
'use strict';
require('chai').should();
const Hogan = require('hogan.js');
const cheerio = require('cheerio');
const path = require('path');
const fs = require('fs');
const partials = require('./load-partials');
const filename = path.resolve(__dirname, '..', 'views', 'partials', 'analytics.html');
describe('Analytics partial', () => {
let compiled;
let locals;
beforeEach(() => {
let template = fs.readFileSync(filename, 'utf8');
compiled = Hogan.compile(template);
});
beforeEach(() => {
locals = {
'ga-id': 'abc'
};
});
it('should render', () => {
let html = compiled.render({});
html.should.equal('');
});
it('should render from the head partial', () => {
let html = partials.render('hmpo-partials-head', locals);
html.should.match(/\/\/www.google-analytics.com\/analytics.js/);
});
it('should render a script tag if a ga-id is given', () => {
let html = compiled.render({ 'ga-id': 'abc' });
let $ = cheerio.load(html);
$('script').length.should.equal(1);
});
it('should load snippet if ga id is supplied', () => {
let html = partials.render('hmpo-partials-analytics', locals);
html.should.match(/\/\/www.google-analytics.com\/analytics.js/);
});
it('should fire ga events for each error', () => {
let html = compiled.render({
'ga-id': 'abc',
'ga-page': '/path',
errorlist: [
{ key: 'KEY1', type: 'TYPE1' },
{ key: 'KEY2', type: 'TYPE2' }
]
});
it('should not render if no ga-id is supplied', () => {
delete locals['ga-id'];
let html = partials.render('hmpo-partials-analytics', locals);
html.should.not.match(/\/\/www.google-analytics.com\/analytics.js/);
});
html.should.match(/eventCategory: 'form validation'/);
html.should.match(/eventAction: 'failed'/);
html.should.match(/eventLabel: "KEY1: TYPE1"/);
html.should.match(/eventLabel: "KEY2: TYPE2"/);
});
it('should not render if a gtm config is supplied', () => {
locals.gtm = { id: 'present' };
let html = partials.render('hmpo-partials-analytics', locals);
html.should.not.match(/\/\/www.google-analytics.com\/analytics.js/);
});
it('should fire custom ga events for each error', () => {
let html = compiled.render({
'ga-id': 'abc',
'ga-page': '/path',
errorlist: [
{ key: 'KEY1', type: 'TYPE1', gaCategory: 'CAT1', gaAction: 'ACTION1', gaLabel: 'LABEL1', gaValue: 12 }
]
});
it('should fire ga events for each error', () => {
locals.errorlist = [
{ key: 'KEY1', type: 'TYPE1' },
{ key: 'KEY2', type: 'TYPE2' }
];
let html = partials.render('hmpo-partials-analytics', locals);
html.should.match(/eventCategory: "CAT1"/);
html.should.match(/eventAction: "ACTION1"/);
html.should.match(/eventLabel: "LABEL1"/);
html.should.match(/eventValue: "12"/);
});
html.should.match(/hitType: 'event'[^]+eventCategory: 'form validation'[^]+eventAction: 'failed'[^]+eventLabel: "KEY1: TYPE1"/);
html.should.match(/hitType: 'event'[^]+eventCategory: 'form validation'[^]+eventAction: 'failed'[^]+eventLabel: "KEY2: TYPE2"/);
});
it('should fire ga events for each event', () => {
let html = compiled.render({
'ga-id': 'abc',
'ga-page': '/path',
gaevents: [
{ gaCategory: 'CAT1', gaAction: 'ACTION1' },
{ gaCategory: 'CAT2', gaAction: 'ACTION2', gaLabel: 'LABEL2', gaValue: 23 }
]
});
it('should fire ga events for each event', () => {
locals.gaevents = [
{ gaCategory: 'CAT1', gaAction: 'ACTION1' },
{ gaCategory: 'CAT2', gaAction: 'ACTION2', gaLabel: 'LABEL2', gaValue: 23 }
];
let html = partials.render('hmpo-partials-analytics', locals);
html.should.match(/eventCategory: "CAT1"/);
html.should.match(/eventAction: "ACTION1"/);
html.should.match(/eventCategory: "CAT2"/);
html.should.match(/eventAction: "ACTION2"/);
html.should.match(/eventLabel: "LABEL2"/);
html.should.match(/eventValue: "23"/);
});
html.should.match(/hitType: 'event'[^]+eventCategory: "CAT1"[^]+eventAction: "ACTION1"/);
html.should.match(/hitType: 'event'[^]+eventCategory: "CAT2"[^]+eventAction: "ACTION2"[^]+eventLabel: "LABEL2"[^]+eventValue: "23"/);
});
});
});
'use strict';
require('chai').should();
const Hogan = require('hogan.js');
const path = require('path');
const fs = require('fs');
const partials = require('./load-partials');
describe('Check all templates compile', () => {
let partialsDirectory = path.resolve(__dirname, '..', 'views', 'partials');
fs.readdirSync(partialsDirectory).forEach(filename => {
describe('partial ' + filename, () => {
let template = fs.readFileSync(path.resolve(partialsDirectory, filename), 'utf8');
it('should compile', () => {
let compiled = Hogan.compile(template);
compiled.should.be.an('object');
});
Object.keys(partials.all).forEach(key => {
describe('partial ' + key, () => {
it('should compile', () => {
let compiled = partials.compile(key);
compiled.should.be.an('object');
});
it('should render', () => {
let html = Hogan.compile(template).render();
html.should.be.a('string');
});
});
});
});
it('should render', () => {
let html = partials.render(key);
html.should.be.a('string');
});
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc