|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var AdLearnOpenPlatform = require('../lib'); |
| 4 | +var Analytics = require('@segment/analytics.js-core').constructor; |
| 5 | +var integration = require('@segment/analytics.js-integration'); |
| 6 | +var sandbox = require('@segment/clear-env'); |
| 7 | +var tester = require('@segment/analytics.js-integration-tester'); |
| 8 | + |
| 9 | +describe('AdLearn Open Platform', function() { |
| 10 | + var adLearnOpenPlatform; |
| 11 | + var analytics; |
| 12 | + var options = { |
| 13 | + retargetingPixelId: '1234', |
| 14 | + events: { |
| 15 | + conversion: 1989, |
| 16 | + 'completed order': 1979 |
| 17 | + } |
| 18 | + }; |
| 19 | + |
| 20 | + beforeEach(function() { |
| 21 | + analytics = new Analytics(); |
| 22 | + adLearnOpenPlatform = new AdLearnOpenPlatform(options); |
| 23 | + analytics.use(AdLearnOpenPlatform); |
| 24 | + analytics.use(tester); |
| 25 | + analytics.add(adLearnOpenPlatform); |
| 26 | + }); |
| 27 | + |
| 28 | + afterEach(function() { |
| 29 | + analytics.restore(); |
| 30 | + analytics.reset(); |
| 31 | + adLearnOpenPlatform.reset(); |
| 32 | + sandbox(); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should have the right settings', function() { |
| 36 | + analytics.compare(AdLearnOpenPlatform, integration('AdLearn Open Platform') |
| 37 | + .option('retargetingPixelId', '') |
| 38 | + .mapping('events')); |
| 39 | + }); |
| 40 | + |
| 41 | + describe('after loading', function() { |
| 42 | + beforeEach(function(done) { |
| 43 | + analytics.once('ready', done); |
| 44 | + analytics.initialize(); |
| 45 | + analytics.page(); |
| 46 | + }); |
| 47 | + |
| 48 | + describe('#page', function() { |
| 49 | + beforeEach(function() { |
| 50 | + analytics.spy(adLearnOpenPlatform, 'load'); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should always trigger the retargeting pixel', function() { |
| 54 | + analytics.page(); |
| 55 | + analytics.loaded('<img src="https://secure.leadback.advertising.com/adcedge/lb?site=695501&betr=1234"/>'); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should trigger the pixel if there is an existing user', function() { |
| 59 | + analytics.identify('userId'); |
| 60 | + analytics.page(); |
| 61 | + analytics.loaded('<img src="https://secure.leadback.advertising.com/adcedge/lb?site=695501&betr=1234"/>'); |
| 62 | + analytics.loaded('<img src="https://secure.leadback.advertising.com/adcedge/lb?site=695501&srvc=1&betr=1234=920204[720]"/>'); |
| 63 | + }); |
| 64 | + }); |
| 65 | + |
| 66 | + describe('#track', function() { |
| 67 | + beforeEach(function() { |
| 68 | + analytics.spy(adLearnOpenPlatform, 'load'); |
| 69 | + }); |
| 70 | + |
| 71 | + it('should not track unmapped events', function() { |
| 72 | + analytics.track('event'); |
| 73 | + analytics.didNotCall(adLearnOpenPlatform.load); |
| 74 | + }); |
| 75 | + |
| 76 | + describe('mapped events', function() { |
| 77 | + it('should track basic conversion with type', function() { |
| 78 | + analytics.track('conversion'); |
| 79 | + analytics.loaded('<img src="https://secure.ace-tag.advertising.com/action/type=1989/bins=1/rich=0/mnum=1516/logs=0/xsstr1=/xsstr2=/xssale=/xsmemid=/"/>'); |
| 80 | + }); |
| 81 | + |
| 82 | + it('should track basic conversion with type and user ID', function() { |
| 83 | + analytics.identify('userId'); |
| 84 | + analytics.track('conversion'); |
| 85 | + analytics.loaded('<img src="https://secure.ace-tag.advertising.com/action/type=1989/bins=1/rich=0/mnum=1516/logs=0/xsstr1=userId/xsstr2=/xssale=/xsmemid=/"/>'); |
| 86 | + }); |
| 87 | + |
| 88 | + it('should track basic conversion with type, user ID, and ecommerce info', function() { |
| 89 | + analytics.identify('userId'); |
| 90 | + analytics.track('completed order', { |
| 91 | + orderId: 'asdf', |
| 92 | + total: 123, |
| 93 | + products: [ |
| 94 | + { |
| 95 | + id: '507f1f77bcf86cd799439011', |
| 96 | + sku: '45790-32', |
| 97 | + name: 'Monopoly: 3rd Edition', |
| 98 | + price: 19, |
| 99 | + quantity: 1, |
| 100 | + category: 'Games' |
| 101 | + }, |
| 102 | + { |
| 103 | + id: '505bd76785ebb509fc183733', |
| 104 | + sku: '46493-32', |
| 105 | + name: 'Uno Card Game', |
| 106 | + price: 3, |
| 107 | + quantity: 2, |
| 108 | + category: 'Games' |
| 109 | + } |
| 110 | + ] |
| 111 | + }); |
| 112 | + analytics.loaded('<img src="https://secure.ace-tag.advertising.com/action/type=1979/bins=1/rich=0/mnum=1516/logs=0/xsstr1=userId/xsstr2=507f1f77bcf86cd799439011,505bd76785ebb509fc183733/xssale=123.00/xsmemid=asdf/"/>'); |
| 113 | + }); |
| 114 | + }); |
| 115 | + }); |
| 116 | + }); |
| 117 | +}); |
0 commit comments