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

@sooro-io/react-gtm-module

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sooro-io/react-gtm-module - npm Package Compare versions

Comparing version 3.0.0 to 3.0.1

2

dist/index.js
"use strict";
var _TagManager = _interopRequireDefault(require("./TagManager"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
module.exports = _TagManager.default;
"use strict";
var _warn = _interopRequireDefault(require("./utils/warn"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
// https://developers.google.com/tag-manager/quickstart

@@ -6,0 +6,0 @@

"use strict";
var _Snippets = _interopRequireDefault(require("./Snippets"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const TagManager = {
dataScript: function (dataLayer) {
dataScript: function (dataLayer, dataLayerName, nonce) {
const script = document.createElement('script');
script.innerHTML = dataLayer;
script.setAttribute('data-testid', dataLayerName);
if (nonce) {
script.setAttribute('nonce', nonce);
}
return script;

@@ -26,3 +30,3 @@ },

};
const dataScript = this.dataScript(snippets.dataLayerVar);
const dataScript = this.dataScript(snippets.dataLayerVar, args.dataLayerName, args.nonce);
return {

@@ -64,3 +68,3 @@ noScript,

const snippets = _Snippets.default.dataLayer(dataLayer, dataLayerName);
const dataScript = this.dataScript(snippets);
const dataScript = this.dataScript(snippets, dataLayerName);
document.head.insertBefore(dataScript, document.head.childNodes[0]);

@@ -67,0 +71,0 @@ }

{
"name": "@sooro-io/react-gtm-module",
"version": "3.0.0",
"version": "3.0.1",
"description": "React Google Tag Manager Module",

@@ -12,8 +12,7 @@ "main": "dist/index.js",

"build": "babel src -d dist --ignore src/__tests__",
"dry": "npm run build && npm publish --dry-run",
"publish": "npm publish --access public"
"prepublish": "npm run build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/sooro-io/react-gtm-module.git"
"url": "https://github.com/sooro-io/react-gtm-module"
},

@@ -39,9 +38,9 @@ "author": {

"devDependencies": {
"@babel/cli": "^7.23.9",
"@babel/core": "^7.24.0",
"@babel/eslint-parser": "^7.23.10",
"@babel/preset-env": "^7.24.0",
"@babel/preset-react": "^7.23.3",
"@babel/cli": "^7.26.4",
"@babel/core": "^7.26.0",
"@babel/eslint-parser": "^7.25.9",
"@babel/preset-env": "^7.26.0",
"@babel/preset-react": "^7.26.3",
"babel-jest": "^29.7.0",
"eslint": "^8.57.0",
"eslint": "^8.57.1",
"jest": "^29.7.0",

@@ -48,0 +47,0 @@ "jest-environment-jsdom": "^29.7.0"

import TagManager from '../TagManager'
describe('TagManager', () => {
// Cleans the environment to ensure tests do not reference resources from previous tests (such as script tags)
beforeEach(() => {
window['dataLayer'] = undefined
window.document.body.innerHTML = ''
window.document.head.innerHTML = ''
})
it('should render tagmanager', () => {

@@ -18,5 +25,22 @@ TagManager.initialize({ gtmId: 'GTM-xxxxxx' })

TagManager.initialize(gtmArgs)
expect(window.dataLayer[1]).toEqual(dataLayer)
expect(window.dataLayer[0]).toEqual(dataLayer)
const dataScript = window.document.querySelector('[data-testid="dataLayer"]')
expect(dataScript.nonce).toBe('')
})
it('should render datalayer script with nonce', () => {
const dataLayer = {
userInfo: 'userInfo',
}
const gtmArgs = {
gtmId: 'GTM-xxxxxx',
dataLayer,
nonce: 'foo',
}
TagManager.initialize(gtmArgs)
expect(window.dataLayer[0]).toEqual(dataLayer)
const dataScript = window.document.querySelector('[data-testid="dataLayer"]')
expect(dataScript.nonce).toBe('foo')
})
it('should render nonce', () => {

@@ -36,3 +60,2 @@ TagManager.initialize({ gtmId: 'GTM-xxxxxx', nonce: 'foo' })

it('should add an event to dataLayer', () => {
window['dataLayer'] = undefined
TagManager.initialize({ gtmId: 'GTM-xxxxxx' })

@@ -44,3 +67,2 @@ TagManager.dataLayer({ dataLayer: { event: 'test' } })

it('should create non-existing dataLayer', () => {
window['dataLayer'] = undefined
TagManager.dataLayer({ dataLayer: { event: 'test' } })

@@ -47,0 +69,0 @@ expect(window['dataLayer']).not.toBeUndefined()

import Snippets from './Snippets'
const TagManager = {
dataScript: function (dataLayer) {
dataScript: function (dataLayer, dataLayerName, nonce) {
const script = document.createElement('script')
script.innerHTML = dataLayer
script.setAttribute('data-testid', dataLayerName)
if (nonce) {
script.setAttribute('nonce', nonce)
}
return script

@@ -27,3 +31,3 @@ },

const dataScript = this.dataScript(snippets.dataLayerVar)
const dataScript = this.dataScript(snippets.dataLayerVar, args.dataLayerName, args.nonce)

@@ -63,3 +67,3 @@ return {

const snippets = Snippets.dataLayer(dataLayer, dataLayerName)
const dataScript = this.dataScript(snippets)
const dataScript = this.dataScript(snippets, dataLayerName)
document.head.insertBefore(dataScript, document.head.childNodes[0])

@@ -66,0 +70,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