Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module.exports = {
FeedItemService: null,
FeedMappingService: null,
FeedService: null,
OfflineConversionFeedService: null,
OfflineConversionFeedService: require('./services/offlineConversionFeedService'),

// Optimization
ExperimentService: null,
Expand Down
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
{
"name": "adwords-api",
"version": "0.0.7",
"description": "Unofficial SDK for Google Adwords API",
"name": "google-adwords-conversion",
"version": "1.0.0",
"description": "Fork: https://www.npmjs.com/package/adwords-api. Added import of offline conversion",
"main": "index.js",
"keywords": [
"adwords",
"google ads",
"api",
"sdk"
"sdk",
"offline",
"conversion"
],
"scripts": {
"test": "gulp test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/fallentech/adwords-api.git"
"url": "git+https://github.com/TimonKK/adwords-api.git"
},
"author": "Talha Asad <[email protected]>",
"author": "[email protected]",
"license": "MIT",
"homepage": "https://github.com/fallentech/adwords-api",
"homepage": "https://github.com/TimonKK/adwords-api.git",
"devDependencies": {
"chai": "3.5.0",
"dotenv": "2.0.0",
Expand Down
85 changes: 85 additions & 0 deletions services/offlineConversionFeedService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
var
_ = require('lodash'),
async = require('async'),
soap = require('soap');

var AdWordsService = require('./adWordsService');
var types = require('../types/offlineConversionFeed');

function Service(options) {
var self = this;
AdWordsService.call(self, options);
self.Collection = types.collection;
self.Model = types.model;
//self.operatorKey = 'cm:operator';

self.parseGetResponse = function(response) {
if (self.validateOnly) {
return {
labels: null
};
} else if (response.rval) {
return {
labels: response.rval.labels || [],
};
} else {
return {};
}
};

self.parseMutateResponse = function(response) {
return self.parseGetResponse(response);
};

self.mutateAddList = function(clientCustomerId, operand, done) {
var operands = operand.map(function (operand) {
if (!operand.isValid()) return done(operand.validationError);
var operation = {};
operation[self.operatorKey] = 'ADD';
operation.operand = operand;
return operation;
});

self.mutate(
{
clientCustomerId: clientCustomerId,
mutateMethod: 'mutate',
operations: operands,
parseMethod: self.mutateAddListResponse
},
done
);
};

self.mutateAddListResponse = function(response) {
if (self.validateOnly) {
return {
links: null
};
} else if (response.rval) {
return {
links: response.rval.links || []
};
} else {
return {};
}
};

// https://developers.google.com/adwords/api/docs/reference/v201607/OfflineConversionFeedService.OfflineConversionFeed
self.selectable = [
'googleClickId',
'conversionName',
'conversionTime',
'conversionValue',
'conversionCurrencyCode'
];

self.xmlns = 'https://adwords.google.com/api/adwords/cm/' + self.version;
self.wsdlUrl = self.xmlns + '/OfflineConversionFeedService?wsdl';
}

Service.prototype = _.create(AdWordsService.prototype, {
constructor: Service
});

module.exports = Service;
33 changes: 33 additions & 0 deletions types/offlineConversionFeed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var _ = require('lodash'),
Backbone = require('backbone');


var conversionTimeR = new RegExp('[0-9]{8} [0-9]{6} [a-zA-Z\/]{2,30}'),
//var conversionTimeR = new RegExp('[0-9]{2}/[0-9]{2}/[0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2} [a-zA-Z\/]{2,30}'),
conversionCurrencyCodeR = new RegExp('[A-Z]{2,10}');


var AccountLabel = Backbone.Model.extend({
validate: function(attrs, options) {
var validationErrors = [];

if ( ! attrs.googleClickId || attrs.googleClickId.length == 0 ) validationErrors.push(Error('googleClickId is empty'));
if ( ! attrs.googleClickId || attrs.googleClickId.length == 0 ) validationErrors.push(Error('conversionName is empty'));
if ( ! (attrs.conversionTime && attrs.conversionTime.match(conversionTimeR)) ) validationErrors.push(Error('conversionTime is invalid'));
if (attrs.conversionValue && _.isNumber(attrs.conversionValue) === false ) validationErrors.push(Error('conversionValue is invalid'));
if (attrs.conversionCurrencyCode && attrs.conversionCurrencyCode.match(conversionCurrencyCodeR) === null ) validationErrors.push(Error('conversionCurrencyCode is invalid'));

if (validationErrors.length > 0) return validationErrors;
}
});


var AccountLabelCollection = Backbone.Collection.extend({
model: AccountLabel
});


module.exports = {
collection: AccountLabelCollection,
model: AccountLabel
};