How to find names of variabels on my own website? - javascript

I want to implement the Trustpilot javascript extension to my own webshop, to make it possible to get automated productreviews based on the people that visit my checkout page.
I managed in Google Tag Manager to set get a trigger, when someone is visiting my /checkout/thankyou page and send a invitation to Trustpilot. They gave me an example JS code to send the inventation to Trustpilot. I'm now only stuck on the actual code to send... I added the sample code below.
Question: They say... that I have to replace the 'VARIABLE_$EMAIL* with my own 'true variables'? But how on earth do I find my true variable names?
Thank you in advance,
Greetings, Jitske
<script>
document.addEventListener('DOMContentLoaded', function() {
const trustpilot_invitation = {
recipientEmail: 'VARIABLE_$EMAIL',
recipientName: 'VARIABLE_$NAME',
referenceId: 'VARIABLE_$ORDERID',
source: 'InvitationScript',
productSkus: 'VARIABLE_$SKU',
products: [{
sku: 'VARIABLE_$SKU',
productUrl: 'VARIABLE_$PRODUCTURL',
imageUrl: 'VARIABLE_$IMAGEURL',
name: 'VARIABLE_$PRODUCTNAME',
}],
};
tp('createInvitation', trustpilot_invitation);
});
</script>

From their support site I found this, which explains a bit more what is needed.
document.addEventListener('DOMContentLoaded', function() {
const trustpilot_invitation_data = {
recipientEmail: 'john#gmail.com',
recipientName: 'John',
referenceId: 'Order_123',
source: 'InvitationScript',
productSkus: ['sku_1', 'sku_2'],
products: [{
sku: 'sku_1',
productUrl: 'https://your_shop.com/product/1',
imageUrl: 'https://your_shop.com/product/images/1',
name: 'test_product_1',
},
{
sku: 'sku_2',
productUrl: 'https://your_shop.com/product/2',
imageUrl: 'https://your_shop.com/product/images/2',
name: 'test_product_2',
}
],
};
tp('createInvitation', trustpilot_invitation_data);
});
So you actually need to parse the email and other info from your page, and add it to this javascript snippet.

Related

Sending data to service array brute force

I can't find an answer to my question, can you help me friends
what kind of requests, I get: facebook, linkedin, reddit
I don't want to write a lot of code, so I want to ask you how I can make
How do I create a check loop, and send the data (the data is the same for all services)
to go through and find the right service. send the right service and data. Again, the data for all services is the same
as you can see, I write a lot of conditional statements, and I don't like it, I want to put
I use ejs, express
I just want to get rid of a lot of code..
everything into one loop and work
var servies = ["facebook", "linkedin", "reddit"]
servies.forEach(service => {
console.log(service);
});
if (service == "linkedin") {
res.render('linkedin', {
id: xssFilters(id),
name: xssFilters(name),
image: xssFilters(photo),
firstName: xssFilters(firstName),
})
}
if (service == "reddit") {
res.render('reddit', {
id: xssFilters(id),
name: xssFilters(name),
image: xssFilters(photo),
firstName: xssFilters(firstName),
})
}
if (service == "facebook") {
res.render('facebook', {
id: xssFilters(id),
name: xssFilters(name),
image: xssFilters(photo),
firstName: xssFilters(firstName),
})
}
You can try
var servies = ["facebook", "linkedin", "reddit"]
servies.forEach(service => {
console.log(service);
res.render(service, {
id: xssFilters(id),
name: xssFilters(name),
image: xssFilters(photo),
firstName: xssFilters(firstName),
})
});
since in your example code, you don't do anything different between the different services, but only replace the string name of the service, and you already have a loop for that.

How do I replace an external javascript array on the Vue js array?

I'm still a beginner in Vue.js and I have a problem. I have this code:
data: function(){
return {
search: '',
zenes: [
{ id: '1', name: 'Jhon Snow', profile_pic: 'https://i.stack.imgur.com/CE5lz.png'},
{ id: '2', name: 'Deanerys Targarian', profile_pic: 'https://i.stack.imgur.com/CE5lz.png'},
{ id: '3', name: 'Jaime Lanister', profile_pic: 'https://i.stack.imgur.com/CE5lz.png'},
{ id: '4', name: 'Tyron Lanister', profile_pic: 'https://i.stack.imgur.com/CE5lz.png'}
]};
},
This code is really good but i would like to use in my application so I would like to change zenes:[....], to an external javascript code:
<script>var zenecim = <%- zenecim %></script>//these are big arrays thousands of items
<script>var zenesrc = <%- zenesrc %></script>
I would like to see like this or something like that:
zenes:[id:(this is the indexof the array),name:zenecim,src:zenesrc]
Thank you very much for the answer.
If you want to receive external data your choices are pretty much limited to either using a prop on a component or you can use an AJAX request with something like Axios for example.
Of course you can set window globals and access them but that is something you really don't want to be doing.
The context of your problem is missing here therefore I can not judge what would be the best pick here.

Bad Request in Discord.js (Node) and cant find out whats causing it

Im coding a bot in Discord.js (Node) and I'm trying to send an embed with the server info, I've got all the code but it keeps causing a Bad Request and I've tried everything I know here's the code:
var FieldsData = [{ name: "Channels", value: msg.guild.channels.size }, { name: "Emojis", value: msg.guild.emojis.size }, { name: "Members", value: msg.guild.members.size }, { name: "Owner", value: msg.guild.owner }, { name: "Roles", value: msg.guild.roles.size }, { name: "Region", value: msg.guild.region }, { name: "Id", value: msg.guild.id }, { name: "Icon", value: msg.guild.iconURL }, { name: "Created At", value: msg.guild.createdAt }];
msg.channel.send('', {
embed: {
color: 37119,
title: "Server info for " + msg.guild.name,
fields: FieldsData
}
});
I've tried the message with just one field and it works,
I've tried it will each field by themselves and it works
but when I put them all together they make a Bad Request,
I've checked every line, every character and I'm just
stumped at what could possibly be causing this,
the max fields is 25 and I don't have that many,
all the variables are valid, none produce 'Null' or 'Undefined',
I've tried different setups of the code layout,
I've tried adding/removing parts, editing parts, replacing bits
here and there but to no avail I cant get it to work at all.
I've been trying to figure this out for 2 hours, I've searched online, docs, etc
Please Note: I'm not that advanced with javascript so if i've made a big mistake then don't be surprised.
"msg" is the object of the message, Example:
Bot.on('message', function (msg) { /*Stuff*/ });
I hope I've explained this enough, I'm using the LATEST version of Discord.js at the time of posting this and I'm not using ANY other extensions, packages, etc
SHORT ANSWER:
Now, don't just ignore this post after I say this (actually read my reasons, the whole thing), but please just use a Rich Embed
LONG ANSWER:
First of all, I strongly suggest using Rich Embeds, as it is easier to play with and edit. Anyways, here:
The first suggestion comes from your message event. In ES6, we now have arrow functions which look like this (arg1, arg2) => {doSomething();}, and using this new feature, your message event handler should look more like this:
client.on('message', msg => {
//Do my thing with that msg object
});
Now back to the point.
Objects are weird k? I believe that this: "Server info for " + msg.guild.name is not allowed. I don't know why, but when I tried to use a variable to display my bot's version, it gave me an error too. So if you want to fix that you have two options:
Recommended: Use Rich Embeds
Not Recommended: Use `${myVar}` instead (Not Tested)
Don't overcomplicate. What is this: ('', You can just do msg.channel.send({embed:{}});
You don't just use variables for the sake of it. What is the point of using FieldsData? It is only used once, and why can't you just do:
msg.channel.send({
embed: {
color: 37119,
title: "Server info for " + msg.guild.name,
fields: [{name: "Channels", value: msg.guild.channels.size}, { name: "Emojis", value: msg.guild.emojis.size }, { name: "Members", value: msg.guild.members.size }, { name: "Owner", value: msg.guild.owner }, { name: "Roles", value: msg.guild.roles.size }, { name: "Region", value: msg.guild.region }, { name: "Id", value: msg.guild.id }, { name: "Icon", value: msg.guild.iconURL }, { name: "Created At", value: msg.guild.createdAt }]
}
});
VERY IMPORTANT NOTE:
Now, you don't give any valid reason why you don't want to use Rich Embeds, because a rich embed is also an object. ;-; So just use a rich embed.
i have scripts that require the use of objects, and they are pre made
I wonder how you get access to your embed if its not stored.... Very interesting.

Foursquare API Not returning photos on the Venue Search

So I'm playing around with the Venues just trying to get it to show some stuff before I both getting specific with my queries. I'm using nodejs and this module.
https://www.npmjs.com/package/foursquarevenues
If that matters. Anyways when I put a call to the api to getVenues with a simple call like:
var params = {
venuePhotos : '1',
near : "Rome, Italy"
};
Everything works fine with the exception that no photos are returned. A standard venue object from this call will look like this:
id: '523b15ce11d2d66df7dca8d0',
name: 'Qlub Radio, Roma',
contact: {},
location:
{ lat: 41.891096,
lng: 12.5106,
labeledLatLngs: [Object],
cc: 'IT',
country: 'Italia',
formattedAddress: [Object] },
categories: [ [Object] ],
verified: false,
stats: { checkinsCount: 3, usersCount: 2, tipCount: 0 },
venueRatingBlacklisted: true,
beenHere: { lastCheckinExpiredAt: 0 },
specials: { count: 0, items: [] },
referralId: 'v-1493396577',
venueChains: [],
hasPerk: false }
Which as far as I can tell returns no photo url for the venue which is contrary to what the documentation suggests. I've been putting in a bunch of different parameters as suggested in other threads and it hasn't changed anything. Am I missing something here?
Thanks.
After looking at the node.js module you're using the getVenues call is hitting the Foursquare venue/search endpoint which doesn't return photos with the search results. Calling exploreVenues in that module will hit the venues/explore endpoint which can return photos by including the venuePhotos=1 parameter (as you've done).
Also, if you only details for a specific venue you can use getVenue and if you only need the photos you can use getVenueAspect.
Hope this helps.

Malformed request when creating billing plan

So I a using the node paypal-rest-sdk module and I'm trying to create a billing plan. Using the documentation here I made this JSON:
const billingPlanAttributes = {
name: 'Subscription',
description: 'Monthly subscription plan',
type: 'INFINITE',
payment_definitions: [{
name: 'Regular monthly infinite payments',
type: 'REGULAR',
frequency_interval: '1',
frequency: 'MONTH',
cycles: '0',
amount: {
currency: 'USD',
amount: '4.99',
},
}],
merchant_preferences: {
cancel_url: 'http://localhost:3000/subscribe/cancel',
return_url: 'http://localhost:3000/subscribe/return',
auto_bill_amount: 'YES',
},
};
But when using the paypal.billingPlan.create(... function I get the error 'MALFORMED_REQUEST', 'Incoming JSON request does not map to API request'. So I guess my JSON is not in the correct format or I'm missing something that is need.
The documentation has a charge_models key but it does not mention that it is required unlike other keys.
If you can point me in the right direction that would be great.
Edit: changed the return url and cancel url to include the full domain but still same error.
There could be more to this, but I noticed one thing wrong with your JSON. Remove commas for items last in a list. After 'amount' and 'merchant_preferences'. JSON is picky.
late answer, I know, but ran in exactly the same issue than you.
In the create function of the billing plan
public function create($apiContext = null, $restCall = null)
{
$payLoad = $this->toJSON();
$json = self::executeCall(
"/v1/payments/billing-plans/",
"POST",
$payLoad,
null,
$apiContext,
$restCall
);
$this->fromJson($json);
return $this;
}
I found out, that the toJSON method always returned false. Why the hell!?!
I did the same as you did and copied the complete sample code into my code. Then it worked as expected. Now I checked, what the difference was in to my code.
I realized, that I used an umlauts (ä,ü,ö) in the name and description of the billing plan. I changed the umlauts to
'ä' => 'ae',
'ö' => 'oe'
'ü' => 'ue'
Then it worked fine! Maybe someone else is running in this issue, too.

Categories

Resources