Skip to content

Instantly share code, notes, and snippets.

@astfarias
astfarias / aidax-gtm-install.js
Created November 9, 2017 18:42
AIDAX Integration Script for Google Tag Manager (GTM)
//This script needs to be fired on All Pages and/or before any AIDAX capture in GTM
<script>
var gtm = google_tag_manager[{{Container ID}}];
try{
// INSERT SCRIPT AIDAX: http://doc.aidax.com.br/
gtm.onHtmlSuccess({{HTML ID}});
} catch(e) {
gtm.onHtmlFailure({{HTML ID}});
@astfarias
astfarias / aidax-example-integration-basic.html
Created September 16, 2017 21:32
AIDAX Basic integration using just a pure HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Experimento AIDAX</title>
</head>
<body>
<h1>Experimento AIDAX</h1>
@astfarias
astfarias / note-js-function-higher-order-function-reduce.js
Last active August 16, 2017 06:00
JS - Functional Programming - Higher-order Functions - reduce()
//Iterate under array to add values with reduce()
var numbers = [0, 1, 5, 7, 3, 8, 9, 10];
var total = numbers.reduce( function( sum, nextValue ) {
return sum + nextValue
},0)
// 43
@astfarias
astfarias / note-js-function-higher-order-function-for.js
Created August 16, 2017 05:49
JS - Functional Programming - Higher-order Functions - for
// Iterate under array to add values
var total = 0;
var numbers = [0, 1, 5, 7, 3, 8, 9, 10];
for (var i = 0; i < numbers.length; i++){
total += numbers[i];
}
console.log("total ", total);
// 43
@astfarias
astfarias / note-js-function-higher-order-function-map.js
Created August 15, 2017 06:08
JS - Functional Programming - Higher-order Functions - map()
// Example of map as a higher-order function because uses a callback function
var animals = [
{ name: 'Fluffykins', species: 'rabbit' },
{ name: 'Caro', species: 'dog' },
{ name: 'Hamilton', species: 'dog' },
{ name: 'Harold', species: 'fish' },
{ name: 'Ursula', species: 'cat' },
];
// map all animals and his species
var names = animals.map(function(animal){
@astfarias
astfarias / aidax-example-Event-login.js
Created August 14, 2017 20:37
AIDAX - Capturing Event Properties Using JS Client ou HTTP request
// Capturing Event
// client-side JS
ax.event({
name: "login",
properties: {
email: "contact@aidax.com.br",
validation: true
}
});
@astfarias
astfarias / aidax-syntax-Event.js
Last active August 14, 2017 20:33
AIDAX - Syntax - Event
// Capturing Event
// client-side JS
ax.event({ // You can also use a concise format (ax({...}))
id: "EVENT ID", // pass this parameter if you have the event id to update it
name: "EVENT NAME", // obligatory
properties: {
property1: "foo",
property2: "bar"
}, // custom properties
callback: function(id) {
@astfarias
astfarias / note-js-function-higher-order-function-filter.js
Last active August 15, 2017 06:02
JS - Functional Programming - Higher-order Functions - filter()
// Example of filter as a higher-order function because uses a callback function
var animals = [
{ name: 'Fluffykins', species: 'rabbit' },
{ name: 'Caro', species: 'dog' },
{ name: 'Hamilton', species: 'dog' },
{ name: 'Harold', species: 'fish' },
{ name: 'Ursula', species: 'cat' },
];
var dogs = animals.filter(function(animal){
@astfarias
astfarias / note-js-function-as-value.js
Last active August 15, 2017 05:50
JS - Functional Programming - Using JS Functions as Value
// Using Function JS as a Value
var triple = function ( x ) {
return x * 3
}
var waffle = triple
waffle(3) // 9
@astfarias
astfarias / aidax-example-Session.js
Created August 10, 2017 17:34
AIDAX - Capturing Session Properties Using JS Client ou HTTP request
// Session properties example
// client-side JS
ax.session({
access_region: "São Paulo",
has_login: "true",
has_checkout: "true"
});
// server-side HTTP request example
curl https://api.aidax.com.br/session?key=<key>&uid=<user id>&p={access_region:"São Paulo",has_login:"true",has_checkout:"true"}