Advertisement
Guest User

Untitled

a guest
Jan 12th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.18 KB | None | 0 0
  1. /**
  2. * Created by sabanades on 28/09/2016.
  3. */
  4.  
  5. /**
  6. *
  7. * Created by jartau on 11/02/16.
  8. * Updated by cvicente on 17/03/16. (Metod)
  9. * PAX adaptation by gmartinez, starting:21/03/16. (PAX)
  10. * Overwrite IVgaCore
  11. *
  12. * Tools for register events in google analytics for PAX
  13. *
  14. */
  15. define('Analytics', [
  16. 'CONFIG',
  17. 'Model',
  18. 'core-analytics'
  19. ], function(CONFIG, model) {
  20.  
  21. var PaxGA = function() {
  22.  
  23. /** @const */
  24. var testUA = 'UA-72755841-12';
  25.  
  26. var UX_UA = 'UA-72755841-17'; //eventos y funnels
  27.  
  28. /** @const */
  29. var allAppsUA = 'UA-53253680-1';
  30.  
  31. /** @const */
  32. var allLanguagesUA = 'UA-72755841-1';
  33.  
  34. /** @const */
  35. var dictionaryUA = { //pageview -> cliente
  36. 'de_AT': 'UA-72755841-23',
  37. 'de_CH': 'UA-72755841-14',
  38. 'de_DE': 'UA-72755841-3',
  39. 'en_GB': 'UA-72755841-10',
  40. 'en_IE': 'UA-72755841-11',
  41. 'es_ES': 'UA-72755841-2',
  42. 'fr_CH': 'UA-72755841-16',
  43. 'fr_BE': 'UA-72755841-20',
  44. 'fr_FR': 'UA-72755841-8',
  45. 'gr_GR': 'UA-72755841-19',
  46. 'it_CH': 'UA-72755841-15',
  47. 'it_IT': 'UA-72755841-4',
  48. 'nl_NL': 'UA-72755841-9',
  49. 'nl_BE': 'UA-72755841-21',
  50. 'pl_PL': 'UA-72755841-5',
  51. 'pt_PT': 'UA-72755841-6',
  52. 'ru_RU': 'UA-72755841-7',
  53. };
  54.  
  55. /** @type {boolean} */
  56. var initialized = false;
  57.  
  58. this.catalgJSON = {};
  59. this.pueJSON = {};
  60. this.storesJSON = {};
  61. this.galleryJSON = {};
  62.  
  63. IVgaCore.call(this);
  64.  
  65. /*
  66. * Cosntant names
  67. *
  68. * Uses these variables to unify the names of actions, events and pages
  69. */
  70. this.pageNames = {
  71. home : 'Home',
  72. gallery : 'Gallery',
  73. doors : 'Doors',
  74. carrousel : 'Carrousel',
  75. planner : 'Planner'
  76. };
  77.  
  78. //category
  79. this.eventCategories = {
  80. trafficOrigin : '(0) [Traffic origin]',
  81. startingPage : '(1) [Starting Page]',
  82. //saveProjectBasicInfo : '(2) [Save Project] Basic Info',
  83. saveProjectStore : '(2) [Save Project] Store',
  84. saveProjectWeb : '(2) [Save Project] IKEAweb',
  85. eCommerce : '(3) [Link to IKEA Shopping List]', //web
  86. // eCommerceStore : '(3) [Link to IKEA Shopping List] Store', //web
  87. iSellStore : '(3) [iSell] Store', //coworker
  88. recoverProjectStore : '(7) [Recover Project] Store',
  89. recoverProjectWeb : '(7) [Recover Project] IKEAweb',
  90. PDFweb : '(7) [Print PDF] IKEAweb',
  91. PDFstore : '(7) [Print PDF] Store',
  92.  
  93. // USABILITY
  94. ux_home : '(10) [Usability] Home',
  95. ux_gallery : '(10) [Usability] Gallery',
  96. ux_carousel : '(10) [Usability] Carousel',
  97. ux_product : '(10) [Usability] Product',
  98. ux_planner : '(10) [Usability] Planner',
  99. ux_planner_menu : '(10) [Usability] Planner Menu',
  100. ux_planner_context : '(10) [Usability] Planner Contextual Menu',
  101. ux_summary : '(10) [Usability] Summary',
  102. ux_recoverProj : '(10) [Usability] RecoverProject',
  103.  
  104. //BEHAVIOUR
  105. behaviour_save_project : '(11) [Behaviour] Save Project'
  106. };
  107.  
  108. //action
  109. this.eventActions = {
  110. gallery : 'Gallery',
  111. carousel : 'Carousel',
  112. product : 'Product',
  113. planner : 'Planner',
  114. recover : 'Recover Project',
  115.  
  116. /*
  117. * USABILIDAD
  118. */
  119. //common/home buttons
  120. homeBtn : 'Go to Home',
  121. galleryBtn : 'Go to Gallery',
  122. productBtn : 'Go to Doors',
  123. plannerBtn : 'Go to Planner',
  124. summaryBtn : 'Go to Summary',
  125. plannerOk : 'Planner Loaded',
  126. recoverBtn : 'Recovery Project',
  127. editProjectBtn : 'Edit Project',
  128. csvBtn : 'Recovery CSV',
  129. backHomeBtn : 'Back to Home',
  130.  
  131. //gallery/product buttons
  132. toggleFiltersBtn : 'Toggle filters',
  133. filtersChecked : 'Filtered by',
  134. showOneProductInterior : 'Open one door',
  135. showOneProductDoors : 'Close one door',
  136. showAllProductInterior : 'Open all doors',
  137. showAllProductDoors : 'Close all doors',
  138.  
  139. //planner
  140. changeBtn : 'Change/New',
  141. measuresBtn : 'Toggle Measures',
  142. changeViewBtn : 'Toggle Plant/Front View',
  143. zoomBtn : 'Zoom By Uppermenu',
  144. rotateBtn : 'Rotation By Uppermenu',
  145. zoomKey : 'Zoom By Keyboard',
  146. rotateKey : 'Rotation By Keyboard',
  147.  
  148. mainTab : 'Change tab',
  149. insideInteriorsTab : 'Change interiors category',
  150. allDoors : 'Select all doors',
  151. allFrames : 'Select all frames',
  152. filterDoor : 'Filter door material',
  153. doorSelected : 'Select door material',
  154. slidingPattern : 'Select sliding pattern',
  155. internalLight : 'Show internal lighting',
  156. presetSelected : 'Preset choosed',
  157. onScrollPlannerMenu : 'Scrolling in Planner Menu',
  158.  
  159. //summary
  160. onScrollSummary : 'Scrolling in Summary',
  161. printBtn : 'Print',
  162. isellBtn : 'Get CSV',
  163. shoppingBtn : 'Go to Shopping List',
  164.  
  165. //BEHAVIOUR
  166. same_frame_int_colour : 'Same frame-interior colour combination?'
  167. };
  168.  
  169. /**
  170. * Return if the service has been initialized with an init() call.
  171. *
  172. * @return {boolean} - Flag initialized
  173. */
  174. this.isInitialized = function() {
  175. return initialized;
  176. };
  177.  
  178. this.getStoreStringFomId = function(){
  179. var storeCode = model.getStoreCode();
  180. var store = "";
  181.  
  182. if ( storeCode != false ) {
  183. for ( st in this.storesJSON){
  184. if ( parseInt(this.storesJSON[st].store_PK) == parseInt(storeCode) ){
  185. store = this.storesJSON[st].store_name +" ("+this.storesJSON[st].store_PK+")";
  186. break;
  187. } else {
  188. store = undefined;
  189. }
  190. }
  191. } else {
  192. if ( model.getMode() == 'web' ) {
  193. store = "web";
  194. } else {
  195. store = undefined;
  196. }
  197. }
  198.  
  199. if ( store == undefined ){
  200. store = "ErrorStore";
  201. console.warn("((GOOGLE ANALYTICS: MAY FAIL)) Store '"+storeCode+"' not able in this country, please check the store ID in the URL.");
  202. }
  203.  
  204. return store;
  205. };
  206.  
  207. /*
  208. * Initialize google analytics configuration for PAX
  209. */
  210. this.init = function( langCode, JSONs) {
  211. initialized = true;
  212.  
  213. this.catalgJSON = JSONs[0];
  214. this.pueJSON = JSONs[1];
  215. this.storesJSON = JSONs[2];
  216. this.galleryJSON = JSONs[3];
  217.  
  218. var store = this.getStoreStringFomId();
  219.  
  220. if (!CONFIG.isProd) {
  221. //test mode
  222. this.addUA(testUA);
  223.  
  224. } else {
  225. var ua = '';
  226. if ( typeof dictionaryUA[langCode] === 'undefined' ){
  227. ua = testUA;
  228. } else {
  229. ua = dictionaryUA[langCode];
  230. }
  231.  
  232. this.addUA([ allAppsUA, allLanguagesUA,ua ]);
  233. }
  234.  
  235. this.setDomain(CONFIG.setDomainUA);
  236.  
  237. this.addDimensionValue('1', langCode, dictionaryUA[langCode]);
  238. this.addDimensionValue('2', store, dictionaryUA[langCode]);
  239.  
  240. this.setEnabled(true);
  241. this.start(false);
  242.  
  243. };
  244.  
  245. /*
  246. * EVENTS
  247. *
  248. * Specific function for events
  249. */
  250. //(0) [Traffic origin]
  251. this.trafficOrigin = function( mode ){
  252. var store = this.getStoreStringFomId();
  253.  
  254. return this.sendEvent(this.eventCategories.trafficOrigin, mode, store );
  255. };
  256.  
  257. //(1) [Starting Page]
  258. //recover project form home
  259. this.homeRecover = function(code,price){
  260. var store = this.getStoreStringFomId();
  261. if ( model.getMode() != "web" ) {
  262. return this.sendEvent(this.eventCategories.recoverProjectStore, store, code, price );
  263. } else {
  264. return this.sendEvent(this.eventCategories.recoverProjectWeb, store, code, price );
  265. }
  266.  
  267. };
  268.  
  269. //ENV Selected
  270. this.ENVselected = function(puerta,price){
  271. var doorName;
  272. if (puerta['id'] != null)
  273. doorName = this.getPUEnamefromPUEref(puerta);
  274. else
  275. doorName = "open wardrobe";
  276. return this.sendEvent(this.eventCategories.startingPage, this.eventActions.gallery, doorName, price );
  277. };
  278.  
  279. this.getPUEnamefromPUEref = function(puerta){
  280.  
  281. // var pue = pueRef.substring(3,6).replace(/^0+/, '');
  282. // var mat = pueRef.substring(9,12).replace(/^0+/, '');
  283. var pue = puerta.id;
  284. var mat = puerta.mat;
  285.  
  286. var ref = this.pueJSON[pue].MAT[mat][0];
  287.  
  288. while ( ref.length != 8 ){
  289. ref = "0"+ref;
  290. }
  291. return this.catalgJSON[ref].name + ": " + this.catalgJSON[ref].fin;
  292. };
  293.  
  294. //PRODUCT Selected
  295. this.PRODUCTselected = function(nomARM){
  296. var options = this.getARMfromName(nomARM);
  297.  
  298. return this.sendEvent(this.eventCategories.startingPage, this.eventActions.product, options[0], options[1] );
  299. };
  300.  
  301. this.getARMfromName = function(nomARM){
  302. var aux = this.galleryJSON.filter_product.measures;
  303. for (var medida in aux){
  304. for (var armario in aux[medida]){
  305. if ( armario == nomARM ){
  306. var arm = aux[medida][armario];
  307. var armario = this.catalgJSON[arm.soft_ref].fin;
  308. var price = this.catalgJSON[arm.soft_ref].price;
  309. return [armario,price];
  310. }
  311. }
  312. }
  313. };
  314.  
  315. //Measures setted, go to planner
  316. this.toPlannerFromMeasures = function(shape){
  317. //measure = measure.join('-');
  318. return this.sendEvent(this.eventCategories.startingPage, this.eventActions.planner, shape );
  319. };
  320.  
  321. //(2) [save project] store
  322. this.saveProject = function( door, price){
  323.  
  324. var store = this.getStoreStringFomId();
  325. if ( model.getMode() == 'web' ){
  326. return this.sendEvent(this.eventCategories.saveProjectWeb, store, door, price );
  327. } else {
  328. return this.sendEvent(this.eventCategories.saveProjectStore, store, door, price );
  329. }
  330.  
  331. };
  332.  
  333. //(3) [link to IKEA shopping list]
  334. //SHOPPING LIST
  335. this.sendToShoppingList = function( door, price){
  336. var store = this.getStoreStringFomId();
  337. return this.sendEvent(this.eventCategories.eCommerce, store, door, price);
  338. };
  339.  
  340. //iSell
  341. this.iSellCoworker = function( door, price ){
  342. var store = this.getStoreStringFomId();
  343. return this.sendEvent(this.eventCategories.iSellStore, store, door, price);
  344. };
  345.  
  346. //(7) [Print PDF]
  347. this.printPDF = function( code, price ){
  348. var store = this.getStoreStringFomId();
  349. if ( model.getMode() == 'web' ){
  350. return this.sendEvent(this.eventCategories.PDFweb , store, code, price);
  351. } else {
  352. return this.sendEvent(this.eventCategories.PDFstore , store, code, price);
  353. }
  354.  
  355. };
  356.  
  357.  
  358. /**
  359. * USABILITY EVENT TRACKING
  360. */
  361. this.uxClick = function(event_category, action_button, status, value){
  362. status = (typeof status == 'undefined' ? 0 : status);
  363. value = (typeof value == 'undefined' ? 0 : value);
  364. return this.sendEvent(this.eventCategories[event_category], this.eventActions[action_button], status, value);
  365. };
  366.  
  367. };
  368.  
  369. return new PaxGA();
  370. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement