digitaldatavalidator

0.0.2 • Public • Published

Digital Data Validator

Description

This script validates the Digital Data Layer of web pages against the specification. The Digital Data Layer (DDL) is a standardised way of exposing data on your eCommerce site. If you implement to the specification, it will mean that you will not have to duplicate your work to expose data to multiple providers (e.g. Triggered Messaging, an analytics provider and a tag management provider).

Instructions

You can either use the validator as a node module (npm install digitaldatavalidator) or in the browser (using the validator-web.js script).

When running on the web, validator will be exposed as a global - from there you can run in the same way as in node:

var result = validator.run(digitalData);

Outline of returned object

The returned object is a dictionary containing 6 keys. 3 of them are booleans and the other 3 are objects that follow the structure of the inputted digitalData object. Since the latter three objects follow a similar structure they can safely be merged if desired.

{
    "isProductsMissingInCategoryPage": Boolean,
    "isProductsMissingInCart": Boolean,
    "hasEmptyObjects": Boolean,
    "emptyObjects": Object,
    "types": Object,
    "missingObjects": Object
}

result.isProductsMissingInCategoryPage

Boolean. Expected to be false.

If the page is a 'category' page, then it is expected to contain a list of products. If no products exist then this object is set to boolean true.

isProductsMissingInCart

Boolean. Expected to be false.

If the cart total price is non-zero, then it is expected for there to be products in the cart. If no products exist then this object is set to boolean true.

hasEmptyObjects

Boolean. Expected to be false.

Whether any empty objects exist in the digitalData object.

emptyObjects

Nested objects, following the structure of the digitalData object. Highlights empty keys.

If an object is empty, its key contains:

{
    "_isEmpty": true
}

If an object is not empty, it is omitted here.

types

Nested objects, following the structure of the digitalData object. Shows whether each key passed or failed the type checks.

Here is an example of a passed type check where the key is an object.

{
    "_typeExpected": "object",
    "_typeFound": "object",
    "_typeCheck": "passed",
}

Here is an example of a failed type check. The key is expected to be a string but instead is a number. Its key contains:

{
    "_typeExpected": "string",
    "_typeFound": "number",
    "_typeCheck": "failed",
}

missingObjects

Nested objects, following the structure of the digitalData object. Some objects are required to exist in the digitalData layer. If these are missing, then their absence is flagged here.

If a required object is missing, its key contains:

{
    "_isMissing": true
}

If a required object exists, nothing for it shows up here.

Rebuilding the web script

You can rebuild the web script by running make buildweb - this will user browserify to re-create the script.

Specification

The script validates against the specification found in the files spec/specType.json and spec/specTypeProduct.json . The latter is an object type that is referenced in the former and is recursive. To change the specification, modify the JSON objects in these files.

Support / Issues

Pull requests / issues / suggestions are welcome on github issues.

Authors

Muhammed Onu Miah, David Henderson

License

Copyright 2014 Triggered Messaging

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Readme

Keywords

Package Sidebar

Install

npm i digitaldatavalidator

Weekly Downloads

2

Version

0.0.2

License

Apache-2.0

Unpacked Size

226 kB

Total Files

13

Last publish

Collaborators

  • dhendo