Skip to content

Commit cf90e8f

Browse files
shahmirnscttcper
authored andcommitted
feat(Piwik): setCustomUrl missing the port info from the URL; se… (angulartics#368)
1 parent d1d75ce commit cf90e8f

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

Diff for: src/lib/providers/piwik/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ export class AppComponent {
5353
}
5454
```
5555
56+
Tracking Custom Variables
57+
```ts
58+
angulartics2.setUserProperties.next({index: 1, name: 'John', value: 123, scope: 'visit'});
59+
```
60+
Note: To track multiple custom variables, call setUserProperties multiple times
61+
62+
Tracking Custom Dimensions
63+
```ts
64+
angulartics2.setUserProperties.next({
65+
dimension1: 'v1.2.3',
66+
dimension2: 'german',
67+
dimension43: 'green',
68+
});
69+
```
70+
Note: Custom Variables and Custom Dimensions cannot be tracked in the same call, and requires separate setUserProperties calls
71+
5672
To track full URLs if there is a hash (#), make sure to enable `settings=>websites=>settings=>page url fragments tracking` in the Piwik dashboard.
5773
5874
Once set up, Angulartics [usage](https://github.com/angulartics/angulartics2#usage) is the same regardless of provider

Diff for: src/lib/providers/piwik/piwik.spec.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('Angulartics2Piwik', () => {
2828
fixture = createRoot(RootCmp);
2929
angulartics2.pageTrack.next({path: '/abc' });
3030
advance(fixture);
31-
expect(_paq).toContain(['setCustomUrl', '/abc']);
31+
expect(_paq).toContain(['setCustomUrl', window.location.origin + '/abc']);
3232
},
3333
)),
3434
);
@@ -199,12 +199,9 @@ describe('Angulartics2Piwik', () => {
199199
fakeAsync(inject([Angulartics2, Angulartics2Piwik],
200200
(angulartics2: Angulartics2, angulartics2Piwik: Angulartics2Piwik) => {
201201
fixture = createRoot(RootCmp);
202-
angulartics2.setUserProperties.next({userId: '1', firstName: 'John', lastName: 'Doe'});
202+
angulartics2.setUserProperties.next({index: 1, name: 'John', value: 123, scope: 'visit'});
203203
advance(fixture);
204-
expect(_paq).toContain([
205-
'setCustomVariable',
206-
{ userId: '1', firstName: 'John', lastName: 'Doe' },
207-
]);
204+
expect(_paq).toContain(['setCustomVariable', 1, 'John', 123, 'visit']);
208205
}
209206
)),
210207
);

Diff for: src/lib/providers/piwik/piwik.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ export class Angulartics2Piwik {
2828

2929
pageTrack(path: string, location?: any) {
3030
try {
31+
if (!window.location.origin) {
32+
(window.location as any).origin = window.location.protocol + '//'
33+
+ window.location.hostname
34+
+ (window.location.port ? ':' + window.location.port : '');
35+
}
3136
_paq.push(['setDocumentTitle', window.document.title]);
32-
_paq.push(['setCustomUrl', path]);
37+
_paq.push(['setCustomUrl', window.location.origin + path]);
3338
_paq.push(['trackPageView']);
3439
} catch (e) {
3540
if (!(e instanceof ReferenceError)) {
@@ -229,7 +234,7 @@ export class Angulartics2Piwik {
229234
const dimensions = this.setCustomDimensions(properties);
230235
try {
231236
if (dimensions.length === 0) {
232-
_paq.push(['setCustomVariable', properties]);
237+
_paq.push(['setCustomVariable', properties.index, properties.name, properties.value, properties.scope]);
233238
}
234239
} catch (e) {
235240
if (!(e instanceof ReferenceError)) {

0 commit comments

Comments
 (0)