I have the below tracking script loading on my site. I want to return "checkout_date" value for GTM purposes. Function will be run through GTM.
Once i have the correct return fucntion js i can implement. I've tried a few things found here but all of them seem to require "var name =" which i don't see present anywhere.
For example, i have tried the below with no success:
function (for(checkout_date in window.hTaxis.criteoBasketTag)) {
if(window.hTaxis.criteoBasketTag.hasOwnProperty(checkout_date)) {
return "checkout_date" = data[checkout_date];
//do something with value;
}
}
<script type="text/javascript">
window.hTaxis = window.hTaxis || {};
window.criteo_q = window.criteo_q || [];
window.criteo_q.push(
{ event: "setAccount", account: 31165 },
{ event: "setSiteType", type: window.hTaxis.siteType },
{ event: "setHashedEmail", email: "" },
{ event: "viewItem", item: 1016454 },
{
event: "viewSearch",
checkin_date: "2020-01-31",
checkout_date: "2020-02-07"
}
);
window.hTaxis.criteoBasketTag = [
{event: "setAccount", account: 31165},
{event: "setSiteType", type: window.hTaxis.siteType},
{event: "setHashedEmail", email: ""},
{
event: "viewBasket", item: [
{
id: 1016454,
price: 39.64,
quantity: 1
}
]
},
{
event: "viewSearch",
checkin_date: "2020-01-31",
checkout_date: "2020-02-07"
}
];
</script>
Related
let object=
[
{
id:`01`,
name:`fish`,
type:null,
care:'owner',
},
{
id:`02`,
name:`fish`,
type:'fresh',
care:'peter',
},
{
id:`03`,
name:`fish`,
type:`fresh`,
care:'amy',
},
{
id:`04`,
name:`fish`,
type:`tank`,
care:'abc',
},
{
id:`05`,
name:`animal`,
type:`pet`,
care:'teen',
},,
{
id:`06`,
name:`animal`,
type:`pet`,
care:'ran',
},
{
id:`07`,
name:`animal`,
type:null,
care:'roh',
},
{
id:`08`,
name:`food`,
type:`veg`,
care:'test',
},
{
id:`09`,
name:`food`,
type:null,
care:'dop',
}
]
object.map((value)=>{
console.log(value.name)
// i am calling function here by passing value.name as a parameter
let gotValue = functionName(value.name);
// using type also
if(typeof value.type!=="string"){
// Do some task here with gotValue
}
})
I have this object and i am getting some value from it for ex getting name from it as i want to pass this name to function but the problem is due to repeat of data the function calling again and again is there any possibility i can run function inside map but with unique value any help ?
as my output is getting like this
fish
fish
fish
animal
animal
animal
and this value.name is passing inside my function so its repeating like this
functionName(fish);
functionName(fish);
functionName(fish);
functionName(animal);
functionName(animal);
functionName(animal);
multiple time function is running with same name and getting duplicate values
just need my function run with unique name
functionName(fish)
functionName(animal);
functionName(food);
as i want to stay inside map function because i am performing some task which can only be possible inside map that's why i need unique value
You can use Set which can be used to test if the object with value already exists or not. It will only call the function only once.
let object = [
{
id: `01`,
name: `fish`,
type: null,
},
{
id: `02`,
name: `fish`,
type: `fresh`,
},
{
id: `03`,
name: `fish`,
type: `tank`,
},
{
id: `04`,
name: `animal`,
type: `pet`,
},
{
id: `05`,
name: `animal`,
type: `wild`,
},
{
id: `06`,
name: `animal`,
type: null,
},
{
id: `07`,
name: `food`,
type: `veg`,
},
{
id: `08`,
name: `food`,
type: null,
},
];
const dict = new Set();
object.map((value) => {
if (!dict.has(value.name)) { // Run only if objet with name is not already existed in dict
dict.add(value.name);
console.log(value.name); // For testing
// functionName(value.name);
}
});
If you want to call the function with two filters then you can use some to find the elements in an array. See I've now declared dict as an array
let object = [{
id: `01`,
name: `fish`,
type: null,
},
{
id: `02`,
name: `fish`,
type: `fresh`,
},
{
id: `03`,
name: `fish`,
type: `tank`,
},
{
id: `04`,
name: `animal`,
type: `pet`,
},
{
id: `05`,
name: `animal`,
type: `wild`,
},
{
id: `06`,
name: `animal`,
type: null,
},
{
id: `07`,
name: `food`,
type: `veg`,
},
{
id: `08`,
name: `food`,
type: null,
},
{
id: `09`,
name: `food`,
type: null,
},
{
id: `10`,
name: `fish`,
type: `tank`,
},
];
const dict = [];
object.map((value) => {
const { name, type } = value;
if (!dict.some((obj) => obj.name === name && obj.type === type)) {
// Run only if objet with name is not already existed in dict
dict.push({ name, type });
console.log(name, type); // For testing
// functionName(value.name);
}
});
.as-console-wrapper { max-height: 100% !important; top: 0; }
I am importing users to Google Suite from a Google sheet using Google Apps Script. I have made "custom attributes" in Google Admin Console, some of them are set to type email. Everything works great except when one user lack those email addresses.
My users are kids, and the emailaddresses are to the kid's parents. One kid might have 1 parent and 1 email. Other kids have 4 parents and 4 emails.
If all variables (epost1, epost2, epost3 and epost4) are filled with email-addresses the user is added. If one of the variables are empty, the script stops with the following message:
GoogleJsonResponseException: API call to directory.users.insert failed
with error: Invalid Input: custom_schema (line 272, file
"nyeMedlemmer")
I tried to put an if-statement in the code, but that was not possible. Is there a way I can tell the script to just ignore those errors?
My code (after the variables are set):
var user = {
primaryEmail: epost,
name: {
givenName: fmnavn,
familyName: etternavn
},
addresses: [
{
type: "home",
formatted: adr
},
{
type: "other",
formatted: adr2
},
{
type: "home",
postalCode: postnr
}
],
phones: [
{
value: mobil,
type: "home"
}
],
emails: [
{
address: epostPriv,
type: "home"
}
],
recoveryEmail: epost1,
locations: [
{
floorName: grad,
type: "desk",
area: "desk"
}
],
gender: {
type: kjonn
},
orgUnitPath: "/Speidere/Stifinnere/"+tropp,
customSchemas: {
Personlig_informasjon: {
skole: skolen,
hensyn: hensynet,
bursdag: dato
},
Innmeldingssvar: {
hjelpe_til: hjelpen,
teste: testen,
merknad: merknaden,
bilde: bildet,
samtykke: samtykket,
innmeldingsdato: innmeldingsdatoen
},
Foresatt: {
foresatt_navn: [
{
value: navn1
},
{
value: navn2,
},
{
value: navn3
},
{
value: navn4
}
],
foresatt_epost: [
{
value: epost1
},
{
value: epost2
},
{
value: epost3
},
{
value: epost4
}
],
foresatt_mob: [
{
value: mobil1
},
{
value: mobil2
},
{
value: mobil3
},
{
value: mobil4
}
]
},//foresatt
},//CustomSchemas
password: passord
}; //var user
user = AdminDirectory.Users.insert(user);
Sometimes all I need is a little break away from the code... I suddenly dawned on my that I could do the if earlier in code:
var epostForesatt = "{value:"+ epost1+"}";
if (epost2 != '') {
var epostForesatt = epostForesatt + ",{value:"+ epost2+"}";
}
if (epost3 != '') {
var epostForesatt = epostForesatt + ",{value:"+ epost3+"}";
}
if (epost4 != '') {
var epostForesatt = epostForesatt + ",{value:"+ epost4+"}";
}
And then later in, down in "var user customSchemas" I edit the code to to use this variable.
Foresatt: {
foresatt_navn: [
{
value: navn1
},
{
value: navn2,
},
{
value: navn3
},
{
value: navn4
}
],
foresatt_epost: [epostForesatt],
So we're working in this system and buildig our own page. We built a form to insert timeline data using a .xwd file. We use javascript to retrieve the data and fill it in a variable to store it. The main page (title:) just has single values, but the actual events should be in an array.
I'm want to use V to fill the array.
$(x_currentPageXML).children().each(function(index, elem){
});
Right now what I have is this and I want to fill the "events" array using the foreach I showed above. Putting the .each inside in the var didn't work and I wouldn't know how else to do it.
var SictTimeline = new function() {
this.loadJS = function () {
$.getScript(x_templateLocation + 'common_html5/js/timeline.js')
.done(function (script, textStatus) {
var make_the_json = $(x_currentPageXML).children().map(function (element) {
return {
title: {
media: {
url: element.getAttribute("url"),
caption: element.getAttribute("tip"),
},
text: {
headline: element.getAttribute("name"),
text: '<p>' + element.getAttribute("text") + '</p>'
}
},
events: {
media: {
url: element.getAttribute("url"),
caption: element.getAttribute("tip"),
},
start_date: {
month: '8',
day: '9',
year: '1963'
},
text: {
headline: element.getAttribute("name"),
text: element.getAttribute("text")
}
}
}
})
var timeline_json = make_the_json; // replace make_the_json() with the JSON object you created
// two arguments: the id of the Timeline container (no '#')
// and the JSON object or an instance of TL.TimelineConfig created from
// a suitable JSON object
window.timeline = new TL.Timeline('timeline-embed', timeline_json);
})
.fail(function (jqxhr, settings, exception) {
console.log('Failed to load the script for the timeline');
});
}
// function called every time the page is viewed after it has initially loaded
this.pageChanged = function() {
}
// function called every time the size of the LO is changed
this.sizeChanged = function() {
}
this.init = function() {
this.loadJS();
// call this function in every model once everything's loaded
x_pageLoaded();
}
}
An example of the xml-file with the values
<?xml version="1.0"?>
<learningObject editorVersion="3" targetFolder="Nottingham" name="Learning Object Title" language="en-GB" navigation="Linear" textSize="12" theme="default" displayMode="fill window" responsive="true">
<SictTimeline linkID="PG1592486441661" name="My page" media="SictTimeline" text="<p>Text for my page</p>
" url="FileLocation + 'media/https___images.genius.com_53c4575fa3f97a8d4b18d69a600afaf0.900x900x1.jpg'" tip="Description for Image 1"></SictTimeline></learningObject>
I guess what you are trying to achieve is to generate an array of objects based on the number (and properties) of elements inside $(x_currentPageXML). For that purpose you need to use the .map() method:
events: $(x_currentPageXML).children().map(function (index, element) {
return {
media: {
url: element.getAttribute("url"),
caption: element.getAttribute("tip"),
},
start_date: {
month: '8',
day: '9',
year: '1963'
},
text: {
headline: element.getAttribute("name"),
text: element.getAttribute("text")
}
}
}).get()
I'm not sure I completely understand the question, but you want to extract stuff from each element in the loop right?
Replace x_currentPageXML with elem inside the loop
var result = []
$(x_currentPageXML).children().each(function (index, elem) {
var make_the_json = {
title: {
media: {
url: elem.getAttribute("url"),
caption: elem.getAttribute("tip"),
},
text: {
headline: elem.getAttribute("name"),
text: '<p>' + elem.getAttribute("text") + '</p>'
}
},
events: [
{
media: {
url: elem.getAttribute("url"),
caption: elem.getAttribute("tip"),
},
start_date: {
month: '8',
day: '9',
year: '1963'
},
text: {
headline: elem.getAttribute("name"),
text: elem.getAttribute("text")
}
}
]
};
result.push(make_the_json)
})
I need help with this error, I need to pass the values of "id1"
and "roll" that I am assigning them in the addEventListener, to the param send function.
Uncaught TypeError: this.paramSend is not a function
<script>
(function() {
'use strict';
Polymer({
is: 'pa-adminuser',
properties: {
id1: {
type: String,
value: '0',
notify: true
},
hide: {
type: Boolean,
value: true
},
roll: {
type: String,
value: '0',
notify: true
}
},
aftersave: function(){
this.$.themed.addEventListener('after-save', function(e) {
this.id1= e.detail.row.id;
this.roll= e.detail.row.roll;
console.log('paramSend1:' + JSON.stringify({ id: this.id1, roll: this.roll }));
this.paramSend(this.id1, this.roll)
});
},
paramSend: function(id2, roll2){
this.PostData1.body = JSON.stringify({ id: id2, roll: roll2 });
this.PostData1.generateRequest();
this._updateData();
},
_updateData: function() {
console.log('UPDATE DATA');
this.async(function() {
//this.$.PostData1.generateRequest();
this.$.GetData3.generateRequest();
console.log('GENERATE REQUEST');
}, 2000);
},
ready: function() {
}
});
})();
</script>
You have to bind your eventHandler to preserve your this context.
this.$.themed.addEventListener('after-save', function(e) {
....
this.paramSend( .. )
}.bind(this) );
Or use a local this ref.
var _self = this;
this.$.themed.addEventListener('after-save', function(e) {
....
_self.paramSend( .. )
});
I found the solution this way, I hope someone helps
aftersave: function(){
var _self = this;
this.$.themed.addEventListener('after-save', function(e) {
_self.id1= e.detail.row.id;
_self.roll= e.detail.row.roll;
console.log('paramSend1:' + JSON.stringify({ id: this.id1, roll: this.roll }));
_self.paramBody = JSON.stringify({ id: this.id1, roll: this.roll });
_self.$.PostData1.body = _self.paramBody;
_self.$.PostData1.generateRequest();
});
},
Currently, I'm writing an app on Node.js 5.2.0 on a Linux box with Redis and Caminte. When trying to add different prototype methods to a database object, the context of what this refers to constantly shifts within our reference. After calling push in modelRules.js, this shifts types. I was looking for some assistance with:
How to consistently reference the instantiation of a specific module (function that accepts a schema object) outside of the module itself. I want to tack on prototype functions such as addModelBelongsTo to a User object, and sadly my function simply seems to break when referencing the internal modifiable data members within the class.
The proper organization of the prototype accessors. Is there a specific style that should be used when referencing the insides of the instantiations of these classes?
Why the instantiation of the class User persists data across multiple instantiations of the class? For self[restructuredModelName] (type of array), whenever I call this method on one instantiation, another instantiation of the other object already contains the data of the first instantiation. This should not be happening.
User.js
module.exports = function (schema) {
const IBANVerificationStatusSymbol = Symbol('IBANVerificationStatus');
const relationalMapper = require('./../relationalMapper');
const userObj = {
id: { type: schema.Number },
firstName: { type: schema.String },
lastName: { type: schema.String },
IBAN: { type: schema.String, unique: true },
IBANVerified: { type: schema.Boolean, default: false },
IBANVerificationCode: { type: schema.String },
BIC: { type: schema.String },
email: { type: schema.String, index: true, unique: true },
password: { type: schema.String },
status: { type: schema.Number, default: 0 },
profilePicture: { type: schema.String },
phone: { type: schema.String, index: true, unique: true },
accessToken: { type: schema.String },
prefix: { type: schema.String, default: '+31' },
updated: { type: schema.Date, default: Date.now() },
created: { type: schema.Date, default: Date.now() },
lastAccessedFeed: { type: schema.Date },
street: { type: schema.String },
streetNumber: { type: schema.String },
postalCode: { type: schema.String },
city: { type: schema.String },
country: { type: schema.String },
FCR: { type: schema.Number, default: 0 },
};
// There's GOTTA be a way to typecheck at compilation
const associationMap = {
Activity: { belongsTo: 'Activity', hasMany: 'activities' },
Client: { belongsTo: null, hasMany: 'clients' },
Group: { belongsTo: 'Group', hasMany: 'groups' },
Mandate: { belongsTo: null, hasMany: 'mandates' },
Transaction: { belongsTo: null, hasMany: 'transactions' },
Update: { belongsTo: null, hasMany: 'updates' },
Reaction: { belongsTo: null, hasMany: 'reactions' },
};
relationalMapper.createRelations(associationMap, userObj, schema);
const User = schema.define('user', userObj, {
});
const setId = function (self, models) {
// self.addClients(1);
};
User.hooks = {
afterInitialize: [setId],
};
User.prototype.obj = userObj;
User.associationMap = associationMap;
User.prototype.associationMap = associationMap;
return User;
};
modelRules.js:
function addModelBelongsTo(modelName, models, modelObjKey, modelRelated) {
const restructuredModelName = `memberOf${modelName}`;
const restructuredModelNameCamel = `addMemberOf${modelName}`;
const currentModels = models;
currentModels[modelObjKey].prototype[restructuredModelNameCamel] = function(modelId) {
const self = this;
return new Promise((resolve, reject) => {
if (self[restructuredModelName].indexOf(modelId) <= -1) {
modelRelated.exists(modelId, function(err, exists) {
if (err || !exists) { reject(new Error(err || 'Doesnt exist')); }
console.log(`This:${self}\nrestructuredModelName:${JSON.stringify(self[restructuredModelName])}`);
self[restructuredModelName].push(modelId);
console.log(`This:${self}\nrestructuredModelName:${restructuredModelName}`);
self.save((saveErr) => {
saveErr ? reject(new Error(saveErr)) : resolve(self);
});
});
} else {
reject(new Error(''));
}
});
};
}