@mediarithmics/plugins-nodejs-sdk
Version:
This is the mediarithmics nodejs to help plugin developers bootstrapping their plugin without having to deal with most of the plugin boilerplate
22 lines (18 loc) • 566 B
text/typescript
import _ from 'lodash';
import { ClickUrlInfo } from '../base/AdRendererInterface';
export function generateEncodedClickUrl(redirectUrls: ClickUrlInfo[]) {
const urls = _.clone(redirectUrls);
return urls.reduceRight((acc, current, index) => {
if (index == urls.length - 1) {
return current.url;
}
return current.url + encodeUrlInfo(acc, current.redirect_count);
}, '');
}
function encodeUrlInfo(url: string, redirectCount: number) {
while (redirectCount > 0) {
url = encodeURIComponent(url);
redirectCount--;
}
return url;
}