Skip to content

Commit cebc3b2

Browse files
giliomeejgroansongsynergyfr
authored
Email preferences to hubspot (#10761)
* Added logging for calls to mautic_proxy In the process of moving from Mautic/Acquia to Hubspot. Starting by adding a log to develop a deeper understanding of requests, in order to prepare for writing the Hubspot part, which would see requests temporarily be sent to both Acquia and Hubspot before turning the Acquia requests off. * Added MauticLog table * Added entry for every call to mautic_proxy * Wrapped DB call in try-except * wip(Mautic): Temporary include a bit that fires Mautic events. * wip(Mautic): create email_preference app * WIP(Mautic): create model in progress * add model, admin, logging url, view, send event to create dummy info * cleanup * migration file * fix csrf issue, url * log the actual data, add placeholders. * replace placeholder with emailpreference event * remove todo * WIP(Mautic): remove tmp footer script * WIP(Mautic): change model representation, allow empty event_data, create test * WIP(Mautic): refactor, and update test * WIP(Mautic): processed_on fieldname change, user_id to integer * WIP(Mautic): remove Mautic Logging * change migration field order * ng lint Co-authored-by: Roan Song <roansong@gmail.com> Co-authored-by: Hendrik Willem Rossouw <synergeticfrost@gmail.com>
1 parent dc872b2 commit cebc3b2

File tree

26 files changed

+431
-48
lines changed

26 files changed

+431
-48
lines changed

app/app/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
'passport',
159159
'quadraticlands',
160160
'mautic_logging',
161+
'email_preference'
161162
]
162163

163164
MIDDLEWARE = [

app/app/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import dashboard.views
3636
import dataviz.d3_views
3737
import dataviz.views
38+
import email_preference.views
3839
import gitcoinbot.views
3940
import healthcheck.views
4041
import kudos.views
@@ -300,6 +301,7 @@
300301
url(r'^api/v1/file_upload/', dashboard.views.file_upload, name='file_upload'),
301302
url(r'^api/v1/mautic/(?P<endpoint>.*)', dashboard.views.mautic_api, name='mautic_api'),
302303
url(r'^api/v1/mautic_profile_save/', dashboard.views.mautic_profile_save, name='mautic_profile_save'),
304+
url(r'^api/v1/email_preference_log/', email_preference.views.email_preference_log, name='email_preference_log'),
303305

304306
# Health check endpoint
305307
re_path(r'^health/', include('health_check.urls')),

app/assets/v2/js/cart.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,19 @@ Vue.component('grants-cart', {
723723
if (response.success_contributions && response.success_contributions.length) {
724724
if (grant.grant_id === response.success_contributions[0].grant_id) {
725725
// grant.error= response.invalid_contributions[0].message;
726+
EmailPreferenceEvent.createEvent({
727+
'alias': 'products',
728+
'data': [
729+
{
730+
'name': 'product',
731+
'attributes': {
732+
'product': 'grants',
733+
'persona': 'grants-contributor',
734+
'action': 'contribute'
735+
}
736+
}
737+
]
738+
});
726739
MauticEvent.createEvent({
727740
'alias': 'products',
728741
'data': [
@@ -1413,6 +1426,19 @@ Vue.component('grants-cart', {
14131426
const res = await fetch(url, saveSubscriptionParams);
14141427
const json = await res.json();
14151428

1429+
EmailPreferenceEvent.createEvent({
1430+
'alias': 'products',
1431+
'data': [
1432+
{
1433+
'name': 'product',
1434+
'attributes': {
1435+
'product': 'grants',
1436+
'persona': 'grants-contributor',
1437+
'action': 'contribute'
1438+
}
1439+
}
1440+
]
1441+
});
14161442
MauticEvent.createEvent({
14171443
'alias': 'products',
14181444
'data': [

app/assets/v2/js/email_preference.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class EmailPreferenceEvent {
2+
3+
static send(data) {
4+
5+
let loggingApi = '/api/v1/email_preference_log/';
6+
7+
fetch(loggingApi, {
8+
method: 'POST',
9+
headers: {
10+
Accept: 'application/json',
11+
'Content-Type': 'application/json'
12+
},
13+
body: JSON.stringify(data)
14+
})
15+
.then(function(response) {
16+
return response.json();
17+
})
18+
.then(function(result) {
19+
console.log(result);
20+
})
21+
.catch(function(error) {
22+
console.log('Request failed', error);
23+
});
24+
}
25+
26+
static createEvent(...obj) {
27+
let baseObj = {
28+
email: document.contxt.email,
29+
customObjects: {}
30+
};
31+
32+
baseObj.customObjects['data'] = obj;
33+
this.send(baseObj);
34+
}
35+
}

app/assets/v2/js/grants/_new.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,19 @@ Vue.mixin({
257257
data: getFormData(data),
258258
headers: headers,
259259
success: response => {
260+
EmailPreferenceEvent.createEvent({
261+
'alias': 'products',
262+
'data': [
263+
{
264+
'name': 'product',
265+
'attributes': {
266+
'product': 'grants',
267+
'persona': 'grants-creator',
268+
'action': 'create'
269+
}
270+
}
271+
]
272+
});
260273
MauticEvent.createEvent({
261274
'alias': 'products',
262275
'data': [

app/assets/v2/js/grants/cart/algorand_extension.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,19 @@ function contributeWithAlgorandExtensionCallback(
655655
.then((response) => {
656656
if (200 <= response.status && response.status <= 204) {
657657
console.log('success', response);
658+
EmailPreferenceEvent.createEvent({
659+
alias: 'products',
660+
data: [
661+
{
662+
name: 'product',
663+
attributes: {
664+
product: 'grants',
665+
persona: 'grants-contributor',
666+
action: 'contribute'
667+
}
668+
}
669+
]
670+
});
658671
MauticEvent.createEvent({
659672
alias: 'products',
660673
data: [

app/assets/v2/js/grants/cart/binance_extension.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,19 @@ const contributeWithBinanceExtension = async(grant, vm) => {
8787
fetchData(apiUrlGrant, 'POST', JSON.stringify(payload)).then(response => {
8888
if (200 <= response.status && response.status <= 204) {
8989
console.log('success', response);
90+
EmailPreferenceEvent.createEvent({
91+
'alias': 'products',
92+
'data': [
93+
{
94+
'name': 'product',
95+
'attributes': {
96+
'product': 'grants',
97+
'persona': 'grants-contributor',
98+
'action': 'contribute'
99+
}
100+
}
101+
]
102+
});
90103
MauticEvent.createEvent({
91104
'alias': 'products',
92105
'data': [

app/assets/v2/js/grants/cart/cosmos_extension.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const contributeWithCosmosExtension = async(grant, vm) => {
2424
});
2525

2626
const from_address = (await client.signer.getAccounts())[0].address;
27-
27+
2828
let atomBalance = (await client.getBalance(from_address, 'uatom')).amount;
2929

3030
if (Number(atomBalance) < amount) {
@@ -71,6 +71,19 @@ const contributeWithCosmosExtension = async(grant, vm) => {
7171

7272
fetchData(apiUrlBounty, 'POST', JSON.stringify(payload)).then(response => {
7373
if (200 <= response.status && response.status <= 204) {
74+
EmailPreferenceEvent.createEvent({
75+
'alias': 'products',
76+
'data': [
77+
{
78+
'name': 'product',
79+
'attributes': {
80+
'product': 'grants',
81+
'persona': 'grants-contributor',
82+
'action': 'contribute'
83+
}
84+
}
85+
]
86+
});
7487
MauticEvent.createEvent({
7588
'alias': 'products',
7689
'data': [

app/assets/v2/js/grants/cart/harmony_extension.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ const contributeWithHarmonyExtension = async(grant, vm) => {
6565
fetchData(apiUrlBounty, 'POST', JSON.stringify(payload)).then(response => {
6666
if (200 <= response.status && response.status <= 204) {
6767
console.log('success', response);
68+
EmailPreferenceEvent.createEvent({
69+
'alias': 'products',
70+
'data': [
71+
{
72+
'name': 'product',
73+
'attributes': {
74+
'product': 'grants',
75+
'persona': 'grants-contributor',
76+
'action': 'contribute'
77+
}
78+
}
79+
]
80+
});
6881
MauticEvent.createEvent({
6982
'alias': 'products',
7083
'data': [

app/assets/v2/js/grants/cart/polkadot_extension.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,19 @@ const contributeWithPolkadotExtension = async(grant, vm, from_address) => {
134134

135135
if (200 <= response.status && response.status <= 204) {
136136
console.log('success', response);
137+
EmailPreferenceEvent.createEvent({
138+
'alias': 'products',
139+
'data': [
140+
{
141+
'name': 'product',
142+
'attributes': {
143+
'product': 'grants',
144+
'persona': 'grants-contributor',
145+
'action': 'contribute'
146+
}
147+
}
148+
]
149+
});
137150
MauticEvent.createEvent({
138151
'alias': 'products',
139152
'data': [

0 commit comments

Comments
 (0)