Skip to content

Commit 1ccd2b4

Browse files
13314 components popupsmart (#18946)
* Update Popupsmart component to version 0.1.0, add new methods for API requests, and introduce a new source for emitting popup form data events. * pnpm update * Refactor lead filtering in new-popup-form-data to streamline response handling and improve performance by eliminating unnecessary array creation. * await paginated results --------- Co-authored-by: Michelle Bergeron <[email protected]>
1 parent 1d006eb commit 1ccd2b4

File tree

5 files changed

+168
-10
lines changed

5 files changed

+168
-10
lines changed

components/popupsmart/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/popupsmart",
3-
"version": "0.0.2",
3+
"version": "0.1.0",
44
"description": "Pipedream Popupsmart Components",
55
"main": "popupsmart.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
}
1518
}
Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,59 @@
1+
import { axios } from "@pipedream/platform";
2+
const LIMIT = 100;
3+
14
export default {
25
type: "app",
36
app: "popupsmart",
4-
propDefinitions: {},
57
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
8+
_baseUrl() {
9+
return "https://app.popupsmart.com/api";
10+
},
11+
_headers(headers = {}) {
12+
return {
13+
"x-token": this.$auth.api_key,
14+
...headers,
15+
};
16+
},
17+
_makeRequest({
18+
$ = this, path, headers, ...opts
19+
}) {
20+
return axios($, {
21+
url: `${this._baseUrl()}/${path}`,
22+
headers: this._headers(headers),
23+
...opts,
24+
});
25+
},
26+
listLeads(args = {}) {
27+
return this._makeRequest({
28+
path: "leads",
29+
...args,
30+
});
31+
},
32+
async *paginate({
33+
fn, params = {}, maxResults = null, ...opts
34+
}) {
35+
let hasMore = false;
36+
let count = 0;
37+
let page = 0;
38+
39+
do {
40+
params.take = LIMIT;
41+
params.skip = LIMIT * page++;
42+
const { leads } = await fn({
43+
params,
44+
...opts,
45+
});
46+
for (const d of leads) {
47+
yield d;
48+
49+
if (maxResults && ++count === maxResults) {
50+
return count;
51+
}
52+
}
53+
54+
hasMore = leads.length;
55+
56+
} while (hasMore);
957
},
1058
},
1159
};
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
2+
import popupsmart from "../../popupsmart.app.mjs";
3+
import sampleEmit from "./test-event.mjs";
4+
5+
export default {
6+
key: "popupsmart-new-popup-form-data",
7+
name: "New Popup Form Data",
8+
description: "Emit new event when a new popup form data is received. [See the documentation](https://popupsmart.com/help/detail/how-to-auto-download-leads-using-an-api)",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
props: {
13+
popupsmart,
14+
db: "$.service.db",
15+
timer: {
16+
type: "$.interface.timer",
17+
default: {
18+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
19+
},
20+
},
21+
campaignId: {
22+
type: "string",
23+
label: "Campaign ID",
24+
description: "The ID of the campaign to get form data from.",
25+
},
26+
},
27+
methods: {
28+
_getLastDate() {
29+
return this.db.get("lastDate") || 0;
30+
},
31+
_setLastDate(lastDate) {
32+
this.db.set("lastDate", lastDate);
33+
},
34+
async startEvent(maxResults = 0) {
35+
const lastDate = this._getLastDate();
36+
const results = this.popupsmart.paginate({
37+
maxResults,
38+
fn: this.popupsmart.listLeads,
39+
headers: {
40+
"x-campaign-id": this.campaignId,
41+
},
42+
});
43+
44+
let leads = [];
45+
for await (const item of results) {
46+
leads.push(item);
47+
}
48+
49+
leads = leads.filter((item) => Date.parse(item.date) > lastDate);
50+
51+
if (leads.length) {
52+
this._setLastDate(Date.parse(leads[0].date));
53+
}
54+
for (const item of leads.reverse()) {
55+
this.$emit(item, {
56+
id: item.id,
57+
summary: `New form data for popup ${this.campaignId}`,
58+
ts: Date.parse(item.date),
59+
});
60+
}
61+
},
62+
},
63+
hooks: {
64+
async deploy() {
65+
await this.startEvent(25);
66+
},
67+
},
68+
async run() {
69+
await this.startEvent();
70+
},
71+
sampleEmit,
72+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export default {
2+
"id":"23839530_099-516c-446-2053fe-9b19-99ff4e267f",
3+
"date":"2025-11-03 21:52:15",
4+
"sessionId":"23839530_099-516c-446-2053fe-9b19-99ff4e267f",
5+
"accountId":1007926,
6+
"url":"https://website.com/",
7+
"page":"/",
8+
"host":"website.com",
9+
"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36",
10+
"device":"Desktop",
11+
"resolution":"1920x1080",
12+
"os":"Windows",
13+
"browser":"Chrome",
14+
"language":"en-US",
15+
"referrer":"https://website.com/main?post_type=property",
16+
"type":"lead",
17+
"campaignId":1234567890,
18+
"location":"{\"ip\":\"123.456.78.90\",\"countryCode\":\"US\",\"country\":\"United States\",\"region\":\"California\",\"regionCode\":\"CA\",\"city\":\"San Francisco\",\"latitude\":\"37.774929\",\"longitude\":\"-122.419416\",\"timezone\":\"America/Los_Angeles\",\"asOrganization\":\"Google Inc.\",\"postalCode\":\"94107\"}",
19+
"meta":{
20+
"utm_campaign":null,
21+
"utm_source":null,
22+
"utm_medium":null,
23+
"utm_content":null,
24+
"utm_term":null
25+
},
26+
"formData":{
27+
"email_input_3GTXBG":"[email protected]"
28+
},
29+
"unsubscribed":null,
30+
"triggerIntegrations":null
31+
}

pnpm-lock.yaml

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)