gtm-support / core Goto Github PK
View Code? Open in Web Editor NEWCore implementation for Google Tag Manager support
Home Page: https://www.npmjs.com/package/@gtm-support/core
License: MIT License
Core implementation for Google Tag Manager support
Home Page: https://www.npmjs.com/package/@gtm-support/core
License: MIT License
The Google Tag Manager (GTM) allows for the customization of the dataLayer
variable name through its configuration. This feature is particularly useful for websites that need to run multiple instances of GTM or wish to avoid naming conflicts with existing JavaScript variables. Currently, the gtm-support
module assumes the use of the default dataLayer
variable name, which limits its flexibility and applicability in environments where custom dataLayer
names are used or multiple GTM containers are deployed.
I propose enhancing the gtm-support
module to support dynamic naming of the dataLayer
variable. This could be achieved by allowing users to specify the name of the dataLayer
variable when initializing the module. The module would then use this custom name in all operations related to the data layer, including pushing events and variables.
The change could involve updating the module's initialization function to accept an additional configuration option, such as dataLayerName
. For example:
interface GtmSupportOptions {
...
/**
* The name of the dataLayer variable to push events.
*
* @example dataLayerName: 'dataLayerDemo'
*
* @default dataLayer
*/
dataLayerName?: string;
}
class GtmSupport {
constructor(options: GtmSupportOptions) {
...
this.options = {
...
dataLayerName: 'dataLayer',
...options,
};
}
// Further implementation...
}
gtm-support
more seamlessly into projects with existing naming conventions or multiple GTM instances.dataLayer
variables.dataLayer
variable used for purposes other than GTM and need to integrate GTM without naming conflicts.dataLayer
name when the custom name is not provided.dataLayer
name to ensure it adheres to JavaScript variable naming conventions and does not conflict with existing global variables.Sometimes there is a need to perform an action after we know exactly when the script is loaded.
The proposal is to add an option or something similar to the trackEvent
function so that we can have raw/pure custom data sent to the data layer.
Something like:
gtm.trackEvent({ custom: 'test' }, { raw: true })
// object in data layer will be: { custom: 'test' }
This can be achieved if we use dataLayer
directly, but I think it would be nice to have the option already here since we also have logging here if debug is enabled.
Also, one more question, what's the reasoning behind in the first place why the defaults are set?
Currently trackEvent
has some prefined values (event, value etc) already set (prefined values are set within here).
Example:
gtm.trackEvent({ custom: 'test' })
// object in data layer will be: { custom: 'test', event: null, value: null …. }
...
Futhermore, first thread started within the nuxt-gtm module
At the moment in https://github.com/gtm-support/core/blob/main/src/assert-is-gtm-id.ts only gtag's for analyticts are accepted.
In order to use this project Google Ads as well, id's with AW-XXXX
need also be accepted.
Regarding method trackView
:
Lines 152 to 166 in a5024c3
Summary: When the plugin is initialized as disabled but with debugging enabled, trackView()
logs an event to console even though it shouldn’t.
Steps to reproduce:
this.options.debug
to truethis.options.enabled
to falsetrackView
Expected:
Log message [GTM-Support]: Dispatching TrackView …
is not present in the console
Actual:
Log message [GTM-Support]: Dispatching TrackView …
is present in the console
The reason why I think this is a bug: The log message made me believe our setup is incorrect because the plugin (even though configured as disabled) claimed it tracked views but nothing turned up in the dataLayer array. Took some time to figure out what actually was happening. The plugin should only log when it actually pushes something to the dataLayer array.
Tool | Version |
---|---|
Package | v1.1.0 |
Node | v12.22.1 |
OS | mac |
Tool | Version |
---|---|
Package | v1.1.0 |
Options "enabled" and "loadScript" are always set to true independently of the passed configuration.
See:
Lines 49 to 56 in c4bbbe5
Was this done on purpose maybe? Or what's the point?
Tool | Version |
---|---|
Package | @gtm-support/vue2-gtm v1.0.0 |
Node | v14.1.0 |
OS | win |
When running a production (Vue) build which uses https://www.npmjs.com/package/@gtm-support/vue2-gtm, the bundle fails to load in IE11 (screenshot below) due to a problem in utils.js from gtm-support/core.
I have a very stubborn 3rd Party Cookie Consent banner which relies of certain data-attributes being present on the script tags in order to allow / block them based on user responses to the consent banner.
Is there a way to add some custom HTML data-attributes & classes to the script tag that initialises the GTM script? In a nice way using the configuration object?
If I were to create an PR for this, is it likely to be accepted?
They want me to inject tags like this if I were using a conventional GTM initialisation snippet
j.setAttributeNode(d.createAttribute('data-ot-ignore'));
j.setAttribute('class','optanon-category-C0001');
To produce something like this
<script src="https://www.googletagmanager.com/gtm.js" data-ot-ignore class="optanon-category-C0001"></script>
Could we provide a config support to load the script in head tag instead of body tag
...
...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.