Skip to content
Permalink
Browse files

Add fallback for ga to video url

  • Loading branch information...
marcomontalbano committed Sep 19, 2019
1 parent 7299c34 commit 2f945a81d81ed5ed8130d7dcb1be0f8a5aa2edae
Showing with 22 additions and 1 deletion.
  1. +6 −1 src/lambda/classes/google-ua.js
  2. +16 −0 src/lambda/classes/google-ua.test.js
@@ -11,14 +11,19 @@ const sendEvent = (...args) => {
const sendLambdaEvent = (event, send = sendEvent) => {
const {
path: functionUrl,
queryStringParameters: {
url
} = {},
headers: {
referer
} = {}
} = event;

const functionName = path.basename(functionUrl);
const category = `Lambda Function - ${functionName}`;
const label = referer ? `referer - ${referer}` : '';
const refererText = referer ? `referer - ${referer}` : '';
const urlText = url ? `videoUrl - ${url}` : '';
const label = refererText ? refererText : urlText;

send(category, 'invoke', label);
}
@@ -19,10 +19,26 @@ describe('google-ua', () => {
path: '/.netlify/functions/image-json',
headers: {
referer: 'https://example.com'
},
queryStringParameters: {
url: 'https://example.com'
}
}, mock);

expect(mock).toBeCalledWith('Lambda Function - image-json', 'invoke', 'referer - https://example.com');
});

it('should send event with a specified url', () => {
const mock = jest.fn();

sendLambdaEvent({
path: '/.netlify/functions/image-json',
queryStringParameters: {
url: 'https://example.com'
}
}, mock);

expect(mock).toBeCalledWith('Lambda Function - image-json', 'invoke', 'videoUrl - https://example.com');
});
});
});

0 comments on commit 2f945a8

Please sign in to comment.
You can’t perform that action at this time.