lfischer

Untitled

Jul 12th, 2017
763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 3.16 KB | None | 0 0
  1. var email = "[email protected]" // input here the email of the client
  2. var email_md5 = "e13743a7f1db7f4246badd6fd6ff54ff" // input here the email of the client hashed in md5 - if email is not available
  3. var email_sha256_md5 = "000e3171a5110c35c69d060112bd0ba55d9631c7c2ec93f1840e4570095b263a" // input here the email of the client hashed in md5 than in sha256 - if md5 not availalble
  4. var accountid = 11532 //input here your account id
  5. var store_id = 17 // input here the store_id
  6. var transaction_id = "tr123456" //input here the current transaction Id
  7. var timestamp = "2017-06-02T12:24:10Z" //input here the timestamp of the time when the conversion happened / ISO 8601
  8. var currency = "EUR" //input here the currency
  9. var itemArray = [
  10.         {
  11.           "id" : "2015-02-12_aime la plagne_landry", // Product ID
  12.           "price" : 23, // Price in partner currency
  13.           "quantity" : 1 // Must be an integral number
  14.         },
  15.         {
  16.           "id" : "otherprod5436",
  17.           "price" : 102,
  18.           "quantity" : 3
  19.         }
  20.       ]; // input here the array of product IDs, unit prices and quantity
  21.  
  22.  
  23. //-----------------------------------------------------
  24. // Do not modify below this point :
  25. var http = new XMLHttpRequest();
  26. var endpoint = "https://widget.criteo.com/m/event?apiKey=omnichannel_direct";
  27. var body = {
  28.   "id" :
  29.   {
  30.     // Email
  31.     "email" :
  32.     {
  33.       "raw" : email
  34.     }
  35.   },
  36.   // IP adress - set it to 127.0.0.1 if not applicable
  37.   "ip" : "127.0.0.1",
  38.   // Partner ID
  39.   "account" : accountid,
  40.   // Outlet type
  41.   "site_type" : "instore",
  42.   // Event array
  43.   "events" : [
  44.     // Sale event
  45.     {
  46.       "event" : "trackTransaction",
  47.       "store_id" : store_id,
  48.       "offline_sale_ingestion" : 1,
  49.       "user_segment" : 17,
  50.       "id" : transaction_id, // Transaction ID
  51.       "timestamp" : timestamp, // UTC timestamp (ISO 8601 with explicit UTC timezone designator 'Z')
  52.       "currency" : currency, // Optional override of the partner's default currency
  53.       // Product array
  54.       "item" : itemArray
  55.     }
  56.   ]
  57. };
  58. http.open("POST", endpoint, true);
  59.  
  60. //Send the proper header information along with the request
  61. http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  62.  
  63. http.onreadystatechange = function() {//Call a function when the state changes.
  64.     if(http.readyState == 4 && http.status == 200) {
  65.         alert(http.responseText);
  66.     }
  67. }
  68. http.send(JSON.stringify(body));
  69.  
  70.  
  71. // if necessary call this function to reformat the Item Array
  72. function formatProducts(productsArray, nameofProductID = "id", nameofproductPrice = "price", nameofQuantity = "quantity") {
  73. //declare the table that is going to be use in our tags
  74. var products = [];
  75. for (var i = 0; i < productsArray.length; i++) {
  76.     products.push({
  77.  
  78.         //copy the id from your table, this is just an example :
  79.         id: productsArray[i][nameofProductID],
  80.  
  81.         //copy the price from your table, this is just an example :
  82.         price: productsArray[i][nameofproductPrice],
  83.  
  84.         //copy the quantity from your table, this is just an example
  85.         quantity: productsArray[i][nameofQuantity]
  86.     });
  87. }
  88. return products;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment