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

redux-gtm

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-gtm - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

src/create-event.js

8

lib/create-event.js

@@ -0,6 +1,8 @@

'use strict';
function createEvent(eventDefinition, prevState, action) {
const event = { event: eventDefinition.eventName || action.type };
var event = { event: eventDefinition.eventName || action.type };
if (typeof eventDefinition.eventFields === 'function') {
const payload = eventDefinition.eventFields(prevState, action);
var payload = eventDefinition.eventFields(prevState, action);
return Object.assign({}, event, payload);

@@ -12,2 +14,2 @@ }

module.exports = createEvent;
module.exports = createEvent;

@@ -1,25 +0,31 @@

const createEvent = require('./create-event');
const validateEvent = require('./validate-event');
const getDataLayer = require('./get-data-layer');
'use strict';
const createMetaReducer = (actionsToTrack, customDataLayer) => reducer => (state, action) => {
const dataLayer = getDataLayer(window, customDataLayer);
var createEvent = require('./create-event');
var validateEvent = require('./validate-event');
var getDataLayer = require('./get-data-layer');
const result = reducer(state, action);
var createMetaReducer = function createMetaReducer(actionsToTrack, customDataLayer) {
return function (reducer) {
return function (state, action) {
var dataLayer = getDataLayer(window, customDataLayer);
const eventDefinition = actionsToTrack[action.type];
if (dataLayer === undefined || !eventDefinition) {
return result;
}
var result = reducer(state, action);
const event = createEvent(eventDefinition, state, action);
const isValidEvent = validateEvent(event, eventDefinition);
var eventDefinition = actionsToTrack[action.type];
if (dataLayer === undefined || !eventDefinition) {
return result;
}
if (isValidEvent) {
dataLayer.push(event);
}
var event = createEvent(eventDefinition, state, action);
var isValidEvent = validateEvent(event, eventDefinition);
return result;
if (isValidEvent) {
dataLayer.push(event);
}
return result;
};
};
};
module.exports = createMetaReducer;
module.exports = createMetaReducer;

@@ -1,26 +0,34 @@

const createEvent = require('./create-event');
const validateEvent = require('./validate-event');
const getDataLayer = require('./get-data-layer');
'use strict';
const createMiddleware = (actionsToTrack, customDataLayer) => store => next => action => {
const dataLayer = getDataLayer(window, customDataLayer);
var createEvent = require('./create-event');
var validateEvent = require('./validate-event');
var getDataLayer = require('./get-data-layer');
const eventDefinition = actionsToTrack[action.type];
var createMiddleware = function createMiddleware(actionsToTrack, customDataLayer) {
return function (store) {
return function (next) {
return function (action) {
var dataLayer = getDataLayer(window, customDataLayer);
if (dataLayer === undefined || !eventDefinition) {
return next(action);
}
var eventDefinition = actionsToTrack[action.type];
const prevState = store.getState();
const event = createEvent(eventDefinition, prevState, action);
if (dataLayer === undefined || !eventDefinition) {
return next(action);
}
const isValidEvent = validateEvent(event, eventDefinition);
var prevState = store.getState();
var event = createEvent(eventDefinition, prevState, action);
if (isValidEvent) {
dataLayer.push(event);
}
var isValidEvent = validateEvent(event, eventDefinition);
return next(action);
if (isValidEvent) {
dataLayer.push(event);
}
return next(action);
};
};
};
};
module.exports = createMiddleware;
module.exports = createMiddleware;

@@ -1,3 +0,7 @@

function createGAevent(eventProps = {}) {
const defaultEvent = {
'use strict';
function createGAevent() {
var eventProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var defaultEvent = {
event: 'REDUX_GTM_GA_EVENT',

@@ -8,3 +12,3 @@ hitType: 'event',

eventLabel: 'unknown label',
eventValue: 'unknown value',
eventValue: 'unknown value'
};

@@ -14,2 +18,2 @@ return Object.assign(defaultEvent, eventProps);

module.exports = createGAevent;
module.exports = createGAevent;

@@ -1,9 +0,13 @@

function emitGApageview(page = 'unknown page') {
'use strict';
function emitGApageview() {
var page = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'unknown page';
return {
event: 'REDUX_GTM_GA_EVENT',
hitType: 'pageview',
page,
page: page
};
}
module.exports = emitGApageview;
module.exports = emitGApageview;

@@ -1,4 +0,7 @@

const { NO_WINDOW_WARNING } = require('./messages');
'use strict';
function getDataLayer (window, customDataLayer) {
var _require = require('./messages'),
NO_WINDOW_WARNING = _require.NO_WINDOW_WARNING;
function getDataLayer(window, customDataLayer) {
if (customDataLayer !== undefined && typeof customDataLayer.push === 'function') {

@@ -15,2 +18,2 @@ return customDataLayer;

module.exports = getDataLayer;
module.exports = getDataLayer;

@@ -1,14 +0,16 @@

const createMiddleware = require('./create-middleware');
const createMetaReducer = require('./create-meta-reducer');
'use strict';
var createMiddleware = require('./create-middleware');
var createMetaReducer = require('./create-meta-reducer');
// Event Helpers
const createGAevent = require('./event-helpers/create-ga-event');
const createGApageview = require('./event-helpers/create-ga-pageview');
var createGAevent = require('./event-helpers/create-ga-event');
var createGApageview = require('./event-helpers/create-ga-pageview');
module.exports = {
createMiddleware,
createMetaReducer,
createMiddleware: createMiddleware,
createMetaReducer: createMetaReducer,
EventHelpers: {
createGAevent,
createGApageview,
createGAevent: createGAevent,
createGApageview: createGApageview
}
};
};

@@ -1,5 +0,7 @@

const NO_WINDOW_WARNING = 'There is no window object, please provide a custom data layer';
'use strict';
var NO_WINDOW_WARNING = 'There is no window object, please provide a custom data layer';
module.exports = {
NO_WINDOW_WARNING,
};
NO_WINDOW_WARNING: NO_WINDOW_WARNING
};

@@ -0,3 +1,5 @@

"use strict";
function validateEvent(event, eventDefinition) {
const hasSchema = eventDefinition.eventSchema !== undefined;
var hasSchema = eventDefinition.eventSchema !== undefined;

@@ -8,7 +10,9 @@ if (!hasSchema) {

const eventKeys = Object.keys(eventDefinition.eventSchema);
const isValid = (key) => eventDefinition.eventSchema[key](event[key]);
var eventKeys = Object.keys(eventDefinition.eventSchema);
var isValid = function isValid(key) {
return eventDefinition.eventSchema[key](event[key]);
};
return eventKeys.every(isValid);
}
module.exports = validateEvent;
module.exports = validateEvent;
{
"name": "redux-gtm",
"version": "0.2.1",
"version": "0.2.2",
"description": "Google Tag Manager integration for Redux and ngrx/store",
"main": "lib/index.js",
"typings": "./index.d.ts",
"files": [
"lib",
"src",
"index.d.ts"
],
"scripts": {

@@ -12,3 +17,6 @@ "test": "jest",

"lint": "eslint src test",
"check": "npm run lint && npm run test"
"check": "npm run lint && npm run test",
"prebuild": "rm -rf lib && mkdir lib",
"build": "babel src --out-dir lib",
"prepublish": "npm run build"
},

@@ -31,2 +39,4 @@ "engines": {

"devDependencies": {
"babel-cli": "^6.18.0",
"babel-preset-latest": "^6.16.0",
"eslint": "^3.8.1",

@@ -33,0 +43,0 @@ "eslint-config-airbnb": "^12.0.0",

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