1 | /**
|
2 | * Group profile methods. Learn more: https://help.mixpanel.com/hc/en-us/articles/360025333632
|
3 | */
|
4 |
|
5 | const {ProfileHelpers} = require('./profile_helpers');
|
6 |
|
7 | class MixpanelGroups extends ProfileHelpers() {
|
8 | constructor(mp_instance) {
|
9 | super();
|
10 | this.mixpanel = mp_instance;
|
11 | this.endpoint = '/groups';
|
12 | }
|
13 |
|
14 | /** groups.set_once(group_key, group_id, prop, to, modifiers, callback)
|
15 | ---
|
16 | The same as groups.set, but adds a property value to a group only if it has not been set before.
|
17 | */
|
18 | set_once(group_key, group_id, prop, to, modifiers, callback) {
|
19 | const identifiers = {$group_key: group_key, $group_id: group_id};
|
20 | this._set(prop, to, modifiers, callback, {identifiers, set_once: true});
|
21 | }
|
22 |
|
23 | /**
|
24 | groups.set(group_key, group_id, prop, to, modifiers, callback)
|
25 | ---
|
26 | set properties on a group profile
|
27 |
|
28 | usage:
|
29 |
|
30 | mixpanel.groups.set('company', 'Acme Inc.', '$name', 'Acme Inc.');
|
31 |
|
32 | mixpanel.groups.set('company', 'Acme Inc.', {
|
33 | 'Industry': 'widgets',
|
34 | '$name': 'Acme Inc.',
|
35 | });
|
36 | */
|
37 | set(group_key, group_id, prop, to, modifiers, callback) {
|
38 | const identifiers = {$group_key: group_key, $group_id: group_id};
|
39 | this._set(prop, to, modifiers, callback, {identifiers});
|
40 | }
|
41 |
|
42 | /**
|
43 | groups.delete_group(group_key, group_id, modifiers, callback)
|
44 | ---
|
45 | delete a group profile permanently
|
46 |
|
47 | usage:
|
48 |
|
49 | mixpanel.groups.delete_group('company', 'Acme Inc.');
|
50 | */
|
51 | delete_group(group_key, group_id, modifiers, callback) {
|
52 | const identifiers = {$group_key: group_key, $group_id: group_id};
|
53 | this._delete_profile({identifiers, modifiers, callback});
|
54 | }
|
55 |
|
56 | /**
|
57 | groups.remove(group_key, group_id, data, modifiers, callback)
|
58 | ---
|
59 | remove a value from a list-valued group profile property.
|
60 |
|
61 | usage:
|
62 |
|
63 | mixpanel.groups.remove('company', 'Acme Inc.', {'products': 'anvil'});
|
64 |
|
65 | mixpanel.groups.remove('company', 'Acme Inc.', {
|
66 | 'products': 'anvil',
|
67 | 'customer segments': 'coyotes'
|
68 | });
|
69 | */
|
70 | remove(group_key, group_id, data, modifiers, callback) {
|
71 | const identifiers = {$group_key: group_key, $group_id: group_id};
|
72 | this._remove({identifiers, data, modifiers, callback});
|
73 | }
|
74 |
|
75 | /**
|
76 | groups.union(group_key, group_id, data, modifiers, callback)
|
77 | ---
|
78 | merge value(s) into a list-valued group profile property.
|
79 |
|
80 | usage:
|
81 |
|
82 | mixpanel.groups.union('company', 'Acme Inc.', {'products': 'anvil'});
|
83 |
|
84 | mixpanel.groups.union('company', 'Acme Inc.', {'products': ['anvil'], 'customer segments': ['coyotes']});
|
85 | */
|
86 | union(group_key, group_id, data, modifiers, callback) {
|
87 | const identifiers = {$group_key: group_key, $group_id: group_id};
|
88 | this._union({identifiers, data, modifiers, callback})
|
89 | }
|
90 |
|
91 | /**
|
92 | groups.unset(group_key, group_id, prop, modifiers, callback)
|
93 | ---
|
94 | delete a property on a group profile
|
95 |
|
96 | usage:
|
97 |
|
98 | mixpanel.groups.unset('company', 'Acme Inc.', 'products');
|
99 |
|
100 | mixpanel.groups.unset('company', 'Acme Inc.', ['products', 'customer segments']);
|
101 | */
|
102 | unset(group_key, group_id, prop, modifiers, callback) {
|
103 | const identifiers = {$group_key: group_key, $group_id: group_id};
|
104 | this._unset({identifiers, prop, modifiers, callback})
|
105 | }
|
106 | }
|
107 |
|
108 | exports.MixpanelGroups = MixpanelGroups;
|