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

google-tag-manager-fn

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

google-tag-manager-fn

Google Tag Manager's functional implementation containing script initialization, datalayer handling & events

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
increased by400%
Maintainers
1
Weekly downloads
 
Created
Source

google-tag-manager-fn

google-tag-manager-fn is google tag manager functional management module. You can add gtm container to your web app via this module. Here are some functions that you can use for the various functionalities of gtm.

Installation

npm install --save google-tag-manager-fn

Usage

Import the module to your code

import GTM from 'google-tag-manager-fn'; // Adds functionalities to GTM variable

Functions

init({ id, preview, auth, events, dataLayerName, dataLayer, reactFlag })
GTM.init({
    id: 'GTM-abc', 
    preview: '', 
    auth: '', 
    events: {}, 
    dataLayerName: 'dataLayer', 
    dataLayer: {}, 
    reactFlag: false,
})

Folowing are the options to be passed :

optionused forrequireddefault value
idGTM container Idyes
previewPreviewing containerno''
authAuth key for using gtmno''
eventsFor Adding events to datalayer for tags to be firedno{}
dataLayerNameData Layer Key for Gtm to look for datanodataLayer
dataLayerobject for adding data to datalayer variableno{}
reactFlagFor returning react components to render in your app as script with dangerouslySetInnerHTMLnofalse
appendDL({ dataLayerName, dataLayer, state, reactFlag, event })
GTM.appendDL({
    dataLayerName: 'dataLayer', 
    dataLayer: {
        value: 'gtm variable',
    }, 
    state: 1,
    reactFlag: false,
    event: 'gtm-value',
})

Folowing are the options to be passed :

optionused forrequireddefault value
dataLayerNameData Layer Key for Gtm to look for datanodataLayer
dataLayerobject for adding data to datalayer variableno{}
state0 : data without event, 1 : data with eventno0
reactFlagFor returning react components to render in your app as script with dangerouslySetInnerHTMLnofalse
eventEvent Name for dataLayer variableno'DLChanged'
fireEvent({ event, data, elementId })
GTM.fireEvent({
    event: 'gtm-event',
    data: {
        value: 'gtm event value',
    }, 
    elementId: '',
})

Folowing are the options to be passed :

optionused forrequireddefault value
eventEvent Name for to be firedno'custom-event'
dataobject for passing it to the custom eventno{}
elementIdstring Id for the event to be attached to or in default case it attaches event to document objectno''

GTM to Catch Events

Firing Tags

You can add Page Views Tags or Tags on the basis of data layer variable values. You can All Page Route Change trigger for your react app. to check for the tag firing conditions.

Events Capture

You can add Custom Html Tag for capturing events that you are firing from your app using this module. (CustomEvent : object should be supported by your browser version.)

<script>
document.addEventListener('ga-event', function(ev){
    // Your data that you have passed from the app in your event will be available in ev.detail.
    console.log(ev.detail); // You data is logged on console.
});
</script>

If you have your app server side rendering try using functions in your user interactive functions or componentDidMount which runs only on browser as the document object might not be present on server side. And use reactFlag option as true for adding the component to your component render function.

You can visit some links for reference:

  • React
  • Google Tag Manager
  • Github Link For Repo
  • Npm Link for the module

Organisation

Gradeup

Keywords

FAQs

Package last updated on 10 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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