forked from angulartics/angulartics2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathibm-digital-analytics.ts
194 lines (174 loc) · 7.17 KB
/
ibm-digital-analytics.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import { Injectable } from '@angular/core';
import { Angulartics2 } from 'angulartics2';
@Injectable({ providedIn: 'root' })
export class Angulartics2IBMDigitalAnalytics {
constructor(private angulartics2: Angulartics2) {
if (typeof window['cmCreatePageviewTag'] !== 'function') {
console.warn(
'Angulartics 2 IBM Digital Analytics Plugin: eluminate.js is not loaded',
);
}
}
startTracking(): void {
this.angulartics2.pageTrack
.pipe(this.angulartics2.filterDeveloperMode())
.subscribe(x => this.pageTrack(x.path));
this.angulartics2.eventTrack
.pipe(this.angulartics2.filterDeveloperMode())
.subscribe(x => this.eventTrack(x.action, x.properties));
}
/**
* Track Page in IBM Digital Analytics
*
* @param path location
*
* @link https://www.ibm.com/support/knowledgecenter/SSPG9M/Implementation/impl_pageviewtag.html
*/
pageTrack(path: string) {
const cmCreatePageviewTag = window['cmCreatePageviewTag'];
cmCreatePageviewTag(path, null, null, null);
}
/**
* Track an event in IBM Digital Analytics
*
* @param action A string corresponding to the type of event that needs to be tracked.
* @param properties The properties that need to be logged with the event.
*/
eventTrack(action: string, properties: any = {}) {
const cmDisplayShops = window['cmDisplayShops'];
switch (action) {
/**
* @description The Product View tag captures information about vdigitalDataiews of product detail pages.
* The Product View tag should be called on the lowest level detail page for products, which is typically
* the Product Details page. You can view example Product View tags below.
*
* @link https://www.ibm.com/support/knowledgecenter/SSPG9M/Implementation/impl_prodviewtag.html
*/
case 'cmCreateProductviewTag':
const cmCreateProductviewTag = window['cmCreateProductviewTag'];
cmCreateProductviewTag(
properties.productId,
properties.productName,
properties.categoryId,
properties.attrbute,
properties.virtualCategory,
);
break;
/**
* @description The Shop Action 5 tag captures data about selected products and which products are present in a shopping cart,
* if any, when the cart is viewed.
*
* @link https://www.ibm.com/support/knowledgecenter/SSPG9M/Implementation/impl_shopact5tag.html
*/
case 'cmCreateShopAction5Tag':
const cmCreateShopAction5Tag = window['cmCreateShopAction5Tag'];
cmCreateShopAction5Tag(
properties.productId,
properties.productName,
properties.quantity,
properties.unitPrice,
properties.categoryId,
properties.attrbute,
properties.extraFields,
properties.virtualCategory,
);
cmDisplayShops();
break;
/**
* @description The Shop Action 9 tag captures data about what products were purchased by a customer.
* Like the Shop Action 5 tag, one tag should be sent for each product line item purchased. These tags should be sent
* on the receipt or other completion page confirming a successful order.
*
* @link https://www.ibm.com/support/knowledgecenter/SSPG9M/Implementation/impl_shopact9tag.html
*/
case 'cmCreateShopAction9Tag':
const cmCreateShopAction9Tag = window['cmCreateShopAction9Tag'];
cmCreateShopAction9Tag(
properties.productId,
properties.productName,
properties.quantity,
properties.unitPrice,
properties.registrationId,
properties.orderId,
properties.orderSubtotal,
properties.categoryId,
properties.attrbute,
properties.extraFields,
);
cmDisplayShops();
break;
/**
* @description The Order tag captures order header information such as Registration ID, order ID, order subtotal,
* and shipping and handling. The Order tag should be sent on the receipt page confirming order completion.
*
* @link https://www.ibm.com/support/knowledgecenter/SSPG9M/Implementation/impl_ordertag.html
*/
case 'cmCreateOrderTag':
const cmCreateOrderTag = window['cmCreateOrderTag'];
cmCreateOrderTag(
properties.orderId,
properties.orderSubtotal,
properties.orderShipping,
properties.registrationId,
properties.registrantCity,
properties.registrantState,
properties.registrantPostalCode,
properties.attrbute,
properties.extraFields,
);
break;
/**
* @description The Registration tag creates a Lifetime Visitor Experience Profile (LIVE Profile) by associating a single
* common Registration ID with the IBM® Digital Analytics permanent cookie set in every browser visiting the tagged site.
*
* @link https://www.ibm.com/support/knowledgecenter/SSPG9M/Implementation/impl_registrationtag.html
*/
case 'cmCreateRegistrationTag':
const cmCreateRegistrationTag = window['cmCreateRegistrationTag'];
cmCreateRegistrationTag(
properties.registrationId,
properties.registrantEmail,
properties.registrantCity,
properties.registrantState,
properties.registrantPostalCode,
properties.registrantCountry,
properties.attrbute,
);
break;
/**
* @description The Element tag is used to track intra-page content in IBM® Digital Analytics. Data collected by
* the Element tag is used to populate values in the Element Categories and Top Viewed Elements reports.
*
* @link https://www.ibm.com/support/knowledgecenter/SSPG9M/Implementation/impl_elementtag.html
*/
case 'cmCreateElementTag':
const cmCreateElementTag = window['cmCreateElementTag'];
cmCreateElementTag(
properties.elementId,
properties.elementCategory,
properties.attrbute,
);
break;
/**
* @description The Conversion Event tag is employed for tracking of general non-commerce conversion events.
* The Conversion Event tag is used to populate values in the Conversion Events Reports and to create Key Segments.
* This tag and the reports it populates enable analysis of a wide variety of site activities.
*
* @link https://www.ibm.com/support/knowledgecenter/SSPG9M/Implementation/impl_conversioneventtag.html
*/
case 'cmCreateConversionEventTag':
const cmCreateConversionEventTag = window['cmCreateConversionEventTag'];
cmCreateConversionEventTag(
properties.eventId,
properties.actionType,
properties.eventCategoryId,
properties.points,
properties.attrbute,
properties.extraFields,
);
break;
default:
console.warn('Unsupported Event Action');
}
}
}