Skip to content

Commit 3a8b321

Browse files
authored
[Components] appsflyer - new components (#17386)
1 parent 5b3a819 commit 3a8b321

File tree

10 files changed

+356
-10
lines changed

10 files changed

+356
-10
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import app from "../../appsflyer.app.mjs";
2+
3+
export default {
4+
key: "appsflyer-get-event-types",
5+
name: "Get Event Types",
6+
description: "Returns a list of the available event types for the specified endpoint type. [See the documentation](https://dev.appsflyer.com/hc/reference/get_event-types-attributing-entity)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
attributingEntity: {
12+
type: "string",
13+
label: "Attributing Entity",
14+
description: "The endpoint type.",
15+
options: [
16+
"appsflyer",
17+
"skadnetwork",
18+
],
19+
},
20+
},
21+
async run({ $ }) {
22+
const {
23+
app,
24+
attributingEntity,
25+
} = this;
26+
27+
const response = await app.getEventTypes({
28+
$,
29+
attributingEntity,
30+
});
31+
32+
$.export("$summary", `Successfully retrieved event types with request ID \`${response.request_id}\`.`);
33+
return response;
34+
},
35+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import app from "../../appsflyer.app.mjs";
2+
3+
export default {
4+
key: "appsflyer-get-message-fields",
5+
name: "Get Message Fields",
6+
description: "Returns a list of the available message fields for each platform. [See the documentation](https://dev.appsflyer.com/hc/reference/get_fields-platform)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
platform: {
12+
type: "string",
13+
label: "Platform",
14+
description: "The platform to retrieve message fields for.",
15+
options: [
16+
"ios",
17+
"android",
18+
"windowsphone",
19+
],
20+
},
21+
},
22+
async run({ $ }) {
23+
const {
24+
app,
25+
platform,
26+
} = this;
27+
28+
const response = await app.getMessageFields({
29+
$,
30+
platform,
31+
});
32+
33+
$.export("$summary", `Successfully retrieved message fields with request ID \`${response.request_id}\`.`);
34+
return response;
35+
},
36+
};
Lines changed: 93 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,99 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "appsflyer",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
appId: {
9+
type: "string",
10+
label: "App ID",
11+
description: "Your AppsFlyer App ID (e.g. `com.my.app`).",
12+
async options() {
13+
const { data } = await this.listApps();
14+
return data.map(({
15+
id: value,
16+
attributes: { name: label },
17+
}) => ({
18+
label,
19+
value,
20+
}));
21+
},
22+
},
23+
},
524
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
25+
getUrl(path, baseUrl = constants.API.HQ1.BASE_URL) {
26+
return `${baseUrl}${path}`;
27+
},
28+
getHeaders() {
29+
const { api_token: apiToken } = this.$auth;
30+
return {
31+
Authorization: `Bearer ${apiToken}`,
32+
};
33+
},
34+
makeRequest({
35+
$ = this, path, baseUrl, ...args
36+
} = {}) {
37+
return axios($, {
38+
...args,
39+
url: this.getUrl(path, baseUrl),
40+
headers: this.getHeaders(),
41+
});
42+
},
43+
post(args = {}) {
44+
return this.makeRequest({
45+
method: "POST",
46+
...args,
47+
});
48+
},
49+
put(args = {}) {
50+
return this.makeRequest({
51+
method: "PUT",
52+
...args,
53+
});
54+
},
55+
listApps(args = {}) {
56+
return this.makeRequest({
57+
baseUrl: constants.API.HQ1.MNG_URL,
58+
path: "/apps",
59+
...args,
60+
});
61+
},
62+
getMessageFields({
63+
platform, ...args
64+
} = {}) {
65+
return this.makeRequest({
66+
baseUrl: constants.API.HQ1.PUSH_URL,
67+
path: `/fields/${platform}`,
68+
...args,
69+
});
70+
},
71+
getEventTypes({
72+
attributingEntity, ...args
73+
} = {}) {
74+
return this.makeRequest({
75+
baseUrl: constants.API.HQ1.PUSH_URL,
76+
path: `/event-types/${attributingEntity}`,
77+
...args,
78+
});
79+
},
80+
getPushApiConfiguration({
81+
appId, ...args
82+
} = {}) {
83+
return this.makeRequest({
84+
baseUrl: constants.API.HQ1.PUSH_URL,
85+
path: `/app/${appId}`,
86+
...args,
87+
});
88+
},
89+
updatePushApiConfiguration({
90+
appId, ...args
91+
} = {}) {
92+
return this.put({
93+
baseUrl: constants.API.HQ1.PUSH_URL,
94+
path: `/app/${appId}`,
95+
...args,
96+
});
997
},
1098
},
11-
};
99+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const HQ1_BASE_URL = "https://hq1.appsflyer.com";
2+
3+
const API = {
4+
HQ1: {
5+
BASE_URL: HQ1_BASE_URL,
6+
PUSH_URL: `${HQ1_BASE_URL}/api/pushapi/v1.0`,
7+
MNG_URL: `${HQ1_BASE_URL}/api/mng`,
8+
},
9+
};
10+
11+
export default {
12+
API,
13+
};

components/appsflyer/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/appsflyer",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream AppsFlyer Components",
55
"main": "appsflyer.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1417
}
15-
}
18+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import app from "../../appsflyer.app.mjs";
3+
4+
export default {
5+
props: {
6+
app,
7+
db: "$.service.db",
8+
http: {
9+
type: "$.interface.http",
10+
customResponse: true,
11+
},
12+
appId: {
13+
propDefinition: [
14+
app,
15+
"appId",
16+
],
17+
},
18+
},
19+
hooks: {
20+
async activate() {
21+
const {
22+
app,
23+
appId,
24+
http,
25+
} = this;
26+
const { endpoints = [] } = await app.getPushApiConfiguration({
27+
appId,
28+
});
29+
30+
await app.updatePushApiConfiguration({
31+
appId,
32+
data: {
33+
endpoints: [
34+
...endpoints,
35+
{
36+
method: "POST",
37+
url: http.endpoint,
38+
event_types: this.getEventTypes(),
39+
attributing_entity: "appsflyer",
40+
enabled: true,
41+
},
42+
],
43+
},
44+
});
45+
},
46+
async deactivate() {
47+
const {
48+
app,
49+
appId,
50+
http,
51+
} = this;
52+
const { endpoints = [] } = await app.getPushApiConfiguration({
53+
appId,
54+
});
55+
56+
await app.updatePushApiConfiguration({
57+
appId,
58+
data: {
59+
endpoints: endpoints.filter(
60+
(endpoint) => endpoint.url !== http.endpoint,
61+
),
62+
},
63+
});
64+
},
65+
},
66+
methods: {
67+
generateMeta() {
68+
throw new ConfigurationError("generateMeta is not implemented");
69+
},
70+
getEventTypes() {
71+
throw new ConfigurationError("getEventTypes is not implemented");
72+
},
73+
processEvent(event) {
74+
if (this.appId && event.app_id !== this.appId) {
75+
return;
76+
}
77+
78+
this.$emit(event, this.generateMeta(event));
79+
},
80+
},
81+
async run({ body }) {
82+
this.http.respond({
83+
status: 200,
84+
});
85+
this.processEvent(body);
86+
},
87+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import common from "../common/webhook.mjs";
2+
3+
export default {
4+
...common,
5+
key: "appsflyer-new-in-app-event-instant",
6+
name: "New In-App Event (Instant)",
7+
description: "Emit new event when an in-app event is recorded, such as a purchase or level completion. [See docs here](https://dev.appsflyer.com/hc/reference/push-api-v2)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
methods: {
12+
...common.methods,
13+
getEventTypes() {
14+
return [
15+
"install-in-app-event",
16+
"organic-install-in-app-event",
17+
"re-engagement-in-app-event",
18+
"re-attribution-in-app-event",
19+
];
20+
},
21+
generateMeta(event) {
22+
return {
23+
summary: `New In-App Event ${event.event_name}`,
24+
id: event.event_id,
25+
ts: Date.parse(event.event_time),
26+
};
27+
},
28+
},
29+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import common from "../common/webhook.mjs";
2+
3+
export default {
4+
...common,
5+
key: "appsflyer-new-install-instant",
6+
name: "New Install (Instant)",
7+
description: "Emit new event when a user installs an app tracked by AppsFlyer. [See docs here](https://dev.appsflyer.com/hc/reference/push-api-v2)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
methods: {
12+
...common.methods,
13+
getEventTypes() {
14+
return [
15+
"install",
16+
"organic-install",
17+
];
18+
},
19+
generateMeta(event) {
20+
return {
21+
summary: `New Install ${event.app_id}`,
22+
id: event.event_id,
23+
ts: Date.parse(event.event_time),
24+
};
25+
},
26+
},
27+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import common from "../common/webhook.mjs";
2+
3+
export default {
4+
...common,
5+
key: "appsflyer-new-uninstall-instant",
6+
name: "New Uninstall (Instant)",
7+
description: "Emit new event when a user uninstalls an app tracked by AppsFlyer. [See docs here](https://dev.appsflyer.com/hc/reference/push-api-v2)",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
methods: {
12+
...common.methods,
13+
getEventTypes() {
14+
return [
15+
"uninstall",
16+
];
17+
},
18+
generateMeta(event) {
19+
return {
20+
summary: `New Uninstall ${event.app_id}`,
21+
id: event.event_id,
22+
ts: Date.parse(event.event_time),
23+
};
24+
},
25+
},
26+
};

0 commit comments

Comments
 (0)