Skip to content

Commit

Permalink
feat(posthog): add option to set a group (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
radanovicnikola authored Aug 5, 2024
1 parent 8808617 commit 1acf25d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/lib/providers/posthog/posthog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('Angulartics2Posthog', () => {
capture: jasmine.createSpy('capture'),
identify: jasmine.createSpy('identify'),
alias: jasmine.createSpy('alias'),
group: jasmine.createSpy('group'),
};

const provider: Angulartics2Posthog = TestBed.inject(Angulartics2Posthog);
Expand Down Expand Up @@ -166,4 +167,16 @@ describe('Angulartics2Posthog', () => {
},
),
));

it('should set group properties', fakeAsync(
inject(
[Angulartics2, Angulartics2Posthog],
(angulartics2: Angulartics2, angulartics2Posthog: Angulartics2Posthog) => {
fixture = createRoot(RootCmp);
angulartics2Posthog.setGroup('company', '123', { name: 'Company name' });
advance(fixture);
expect(posthog.group).toHaveBeenCalledWith('company', '123', { name: 'Company name' });
}
)
))
});
10 changes: 10 additions & 0 deletions src/lib/providers/posthog/posthog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,14 @@ export class Angulartics2Posthog {
}
}
}

setGroup(groupType: string, groupKey: string, properties: any) {
try {
posthog.group(groupType, groupKey, properties);
} catch (e) {
if (!(e instanceof ReferenceError)) {
throw e;
}
}
}
}

0 comments on commit 1acf25d

Please sign in to comment.