Skip to content

Commit

Permalink
fix: Ability to push absolutely custom data layer (#320)
Browse files Browse the repository at this point in the history
- added ability to push custom data layer
- cleanup and remove repeated code
  • Loading branch information
GreatKostya authored and scttcper committed Nov 30, 2018
1 parent abfd61d commit 65fe8d0
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions src/lib/providers/gtm/gtm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,24 @@ export class Angulartics2GoogleTagManager {
}

pageTrack(path: string) {
if (typeof dataLayer !== 'undefined' && dataLayer) {
dataLayer.push({
'event': 'Page View',
'content-name': path,
'userId': this.angulartics2.settings.gtm.userId
});
this.pushLayer({
'event': 'Page View',
'content-name': path,
'userId': this.angulartics2.settings.gtm.userId
});
}

/**
* Send Data Layer
*
* @layer data layer object
*/
pushLayer(layer: any) {
if (typeof dataLayer === 'undefined' && !dataLayer) {
return;
}

dataLayer.push(layer);
}

/**
Expand All @@ -61,18 +72,16 @@ export class Angulartics2GoogleTagManager {
// Set a default GTM category
properties = properties || {};

if (typeof dataLayer !== 'undefined' && dataLayer) {
dataLayer.push({
event: properties.event || 'interaction',
target: properties.category || 'Event',
action: action,
label: properties.label,
value: properties.value,
interactionType: properties.noninteraction,
userId: this.angulartics2.settings.gtm.userId,
...properties.gtmCustom
});
}
this.pushLayer({
event: properties.event || 'interaction',
target: properties.category || 'Event',
action: action,
label: properties.label,
value: properties.value,
interactionType: properties.noninteraction,
userId: this.angulartics2.settings.gtm.userId,
...properties.gtmCustom
});
}

/**
Expand Down

0 comments on commit 65fe8d0

Please sign in to comment.