Google Tag Manager Functional
source link: https://www.tuicool.com/articles/hit/26Rvya7
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
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 :
option used for required default valueid
GTM container Id
yes
preview
Previewing container
no
''
auth
Auth key for using gtm
no
''
events
For Adding events to datalayer for tags to be fired
no
{}
dataLayerName
Data Layer Key for Gtm to look for data
no
dataLayer
dataLayer
object for adding data to datalayer variable
no
{}
reactFlag
For returning react components to render in your app as script with dangerouslySetInnerHTML
no
false
appendDL({ dataLayerName, dataLayer, state, reactFlag, event })
GTM.init({ dataLayerName: 'dataLayer', dataLayer: { value: 'gtm variable', }, state: 1, reactFlag: false, event: 'gtm-value', })
Folowing are the options to be passed :
option used for required default valuedataLayerName
Data Layer Key for Gtm to look for data
no
dataLayer
dataLayer
object for adding data to datalayer variable
no
{}
state
0 : data without event, 1 : data with event
no
0
reactFlag
For returning react components to render in your app as script with dangerouslySetInnerHTML
no
false
event
Event Name for dataLayer variable
no
'DLChanged'
fireEvent({ event, data, elementId })
GTM.fireEvent({ event: 'gtm-event', data: { value: 'gtm event value', }, elementId: '', })
Folowing are the options to be passed :
option used for required default valueevent
Event Name for to be fired
no
'custom-event'
data
object for passing it to the custom event
no
{}
elementId
string Id for the event to be attached to or in default case it attaches event to document object
no
''
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.
Links
You can visit some links for reference:
Organisation
Recommend
-
6
Tracking Pixels with Google Tag Manager Reading Time: 3 minutes Introduction Hi Everyone! This is my first blog and in this, I’ll try to explain how we can use Google Tag Manager to...
-
8
Save time, avoid editing code and easily create custom events by configuring your analytics setup via GTM. Tim Jensen on September 21, 2021 at 11:16 am...
-
3
How to track 404 errors in Google Tag Manager Jul 03, 2016 Google Tag Manager (GTM) enabl...
-
1
-
7
-
5
Not FoundYou just hit a route that doesn't exist... the sadness.LoginRadius empowers businesses to deliver a delightful customer experience and win customer trust. Using the LoginRadius Identity...
-
11
Introduction Before setting non technical cookies, the GDPR requires that your website visitors authorize you to do so. So, before setting them, you should show a highly visible banner/popup where you write something like th...
-
14
110 Top SEO Tools That Are 100% Free If you’re looking to get started with SEO or want to achieve better results, here are 110 of the best free SEO tools yo...
-
36
Marketo Form Listener for Google Tag Manager (GTM)
-
3
Learning a new skill, like Google Analytics 4, is intimidating. Add to this the fact that there’s a looming deadline, and you can’t afford to be drag...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK