Skip to content

Commit

Permalink
chore(build): Generate latest bundle [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
alexs-mparticle committed Sep 26, 2024
1 parent 3e4d042 commit 0f6da8e
Show file tree
Hide file tree
Showing 2 changed files with 503 additions and 0 deletions.
250 changes: 250 additions & 0 deletions dist/BingAdsEventForwarder.common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
Object.defineProperty(exports, '__esModule', { value: true });

/*!
* isobject <https://github.com/jonschlinkert/isobject>
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/

function isObject(val) {
return val != null && typeof val === 'object' && Array.isArray(val) === false;
}

// Copyright 2016 mParticle, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.



var name = 'Bing';
var moduleId = 107;
var MessageType = {
SessionStart: 1,
SessionEnd: 2,
PageView: 3,
PageEvent: 4,
CrashReport: 5,
OptOut: 6,
Profile: 14,
Commerce: 16,
};

var constructor = function() {
var self = this;
var isInitialized = false;
var forwarderSettings = null;
var reportingService = null;

self.name = name;

function initForwarder(settings, service, testMode) {
forwarderSettings = settings;
reportingService = service;

try {
if (!testMode) {
(function(window, document, tag, url, queue) {
var f;
var n;
var i;
(window[queue] = window[queue] || []),
(window.uetq = window.uetq || []),
(f = function() {
var obj = {
ti: forwarderSettings.tagId,
q: window.uetq,
};
(obj.q = window[queue]),
(window[queue] = new UET(obj)),
window[queue].push('pageLoad');
}),
(n = document.createElement(tag)),
(n.src = url),
(n.async = 1),
(n.onload = n.onreadystatechange = function() {
var state = this.readyState;
(state &&
state !== 'loaded' &&
state !== 'complete') ||
(f(), (n.onload = n.onreadystatechange = null));
}),
(i = document.getElementsByTagName(tag)[0]),
i.parentNode.insertBefore(n, i);
})(window, document, 'script', '//bat.bing.com/bat.js', 'uetq');

if (window.uetq && window.queue && window.queue.length > 0) {
for (
var i = 0, length = window.queue.length;
i < length;
i++
) {
processEvent(window.queue[i]);
}

window.queue.length = 0;
}
}

isInitialized = true;
return 'Successfully initialized: ' + name;
} catch (e) {
return "Can't initialize forwarder: " + name + ': ' + e;
}
}

function processEvent(event) {
if (!isInitialized) {
return "Can't send to forwarder: " + name + ', not initialized';
}

var reportEvent = false;
try {
if (
event.EventDataType == MessageType.PageEvent ||
event.EventDataType == MessageType.PageView
) {
reportEvent = true;
logEvent(event);
} else if (
event.EventDataType == MessageType.Commerce &&
event.ProductAction &&
event.ProductAction.ProductActionType ==
mParticle.ProductActionType.Purchase
) {
reportEvent = true;
logPurchaseEvent(event);
}

if (reportEvent && reportingService) {
reportingService(self, event);
return 'Successfully sent to forwarder: ' + name;
}
} catch (e) {
return "Can't send to forwarder: " + name + ' ' + e;
}
}

function logEvent(event) {
if (!isInitialized) {
return (
"Can't log event on forwarder: " + name + ', not initialized'
);
}

try {
var obj = createUetObject(event, 'pageLoad');

window.uetq.push(obj);
} catch (e) {
return "Can't log event on forwarder: " + name + ': ' + e;
}

return 'Successfully logged event from forwarder: ' + name;
}

function logPurchaseEvent(event) {
if (!isInitialized) {
return (
"Can't log purchase event on forwarder: " +
name +
', not initialized'
);
}

if (
event.ProductAction.TotalAmount === undefined ||
event.ProductAction.TotalAmount === null
) {
return "Can't log purchase event without a total amount on product action";
}

try {
var obj = createUetObject(event, 'eCommerce');
obj.gv = event.ProductAction.TotalAmount;

window.uetq.push(obj);
} catch (e) {
return "Can't log commerce event on forwarder: " + name + ': ' + e;
}
}

function createUetObject(event, action) {
var obj = {
ea: action,
ec: window.mParticle.EventType.getName(event.EventCategory),
el: event.EventName,
};

if (event.CustomFlags && event.CustomFlags['Bing.EventValue']) {
obj.ev = event.CustomFlags['Bing.EventValue'];
}

return obj;
}

this.init = initForwarder;
this.process = processEvent;
};

function getId() {
return moduleId;
}

function register(config) {
if (!config) {
console.log(
'You must pass a config object to register the kit ' + name
);
return;
}

if (!isObject(config)) {
console.log(
"'config' must be an object. You passed in a " + typeof config
);
return;
}

if (isObject(config.kits)) {
config.kits[name] = {
constructor: constructor,
};
} else {
config.kits = {};
config.kits[name] = {
constructor: constructor,
};
}
console.log(
'Successfully registered ' + name + ' to your mParticle configuration'
);
}

if (typeof window !== 'undefined') {
if (window && window.mParticle && window.mParticle.addForwarder) {
window.mParticle.addForwarder({
name: name,
constructor: constructor,
getId: getId,
});
}
}

var BingAdsEventForwarder = {
register: register,
};
var BingAdsEventForwarder_1 = BingAdsEventForwarder.register;

exports.default = BingAdsEventForwarder;
exports.register = BingAdsEventForwarder_1;
Loading

0 comments on commit 0f6da8e

Please sign in to comment.