Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion components/popupsmart/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/popupsmart",
"version": "0.0.2",
"version": "0.1.0",
"description": "Pipedream Popupsmart Components",
"main": "popupsmart.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.0"
}
}
56 changes: 52 additions & 4 deletions components/popupsmart/popupsmart.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,59 @@
import { axios } from "@pipedream/platform";
const LIMIT = 100;

export default {
type: "app",
app: "popupsmart",
propDefinitions: {},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://app.popupsmart.com/api";
},
_headers(headers = {}) {
return {
"x-token": this.$auth.api_key,
...headers,
};
},
_makeRequest({
$ = this, path, headers, ...opts
}) {
return axios($, {
url: `${this._baseUrl()}/${path}`,
headers: this._headers(headers),
...opts,
});
},
listLeads(args = {}) {
return this._makeRequest({
path: "leads",
...args,
});
},
async *paginate({
fn, params = {}, maxResults = null, ...opts
}) {
let hasMore = false;
let count = 0;
let page = 0;

do {
params.take = LIMIT;
params.skip = LIMIT * page++;
const { leads } = await fn({
params,
...opts,
});
for (const d of leads) {
yield d;

if (maxResults && ++count === maxResults) {
return count;
}
}

hasMore = leads.length;

} while (hasMore);
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import popupsmart from "../../popupsmart.app.mjs";
import sampleEmit from "./test-event.mjs";

export default {
key: "popupsmart-new-popup-form-data",
name: "New Popup Form Data",
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)",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
popupsmart,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
campaignId: {
type: "string",
label: "Campaign ID",
description: "The ID of the campaign to get form data from.",
},
},
methods: {
_getLastDate() {
return this.db.get("lastDate") || 0;
},
_setLastDate(lastDate) {
this.db.set("lastDate", lastDate);
},
async startEvent(maxResults = 0) {
const lastDate = this._getLastDate();
let leads = this.popupsmart.paginate({
maxResults,
fn: this.popupsmart.listLeads,
headers: {
"x-campaign-id": this.campaignId,
},
});

let responseArray = [];
for await (const lead of leads) {
if (Date.parse(lead.date) > lastDate) {
responseArray.push(lead);
}
}

responseArray = responseArray.filter((item) => Date.parse(item.date) > lastDate);

if (responseArray.length) {
this._setLastDate(Date.parse(responseArray[0].date));
}
for (const item of responseArray.reverse()) {
this.$emit(item, {
id: item.id,
summary: `New form data for popup ${this.campaignId}`,
ts: Date.parse(item.date),
});
}
},
},
hooks: {
async deploy() {
await this.startEvent(25);
},
},
async run() {
await this.startEvent();
},
sampleEmit,
};
31 changes: 31 additions & 0 deletions components/popupsmart/sources/new-popup-form-data/test-event.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export default {
"id":"23839530_099-516c-446-2053fe-9b19-99ff4e267f",
"date":"2025-11-03 21:52:15",
"sessionId":"23839530_099-516c-446-2053fe-9b19-99ff4e267f",
"accountId":1007926,
"url":"https://website.com/",
"page":"/",
"host":"website.com",
"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36",
"device":"Desktop",
"resolution":"1920x1080",
"os":"Windows",
"browser":"Chrome",
"language":"en-US",
"referrer":"https://website.com/main?post_type=property",
"type":"lead",
"campaignId":1234567890,
"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\"}",
"meta":{
"utm_campaign":null,
"utm_source":null,
"utm_medium":null,
"utm_content":null,
"utm_term":null
},
"formData":{
"email_input_3GTXBG":"email@example.com"
},
"unsubscribed":null,
"triggerIntegrations":null
}
Loading
Loading