Skip to content

Commit

Permalink
add browser user agent in case the target matomo rate limits bots
Browse files Browse the repository at this point in the history
  • Loading branch information
diosmosis committed Sep 13, 2024
1 parent 85adbe5 commit 9e78885
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { debugLog, log, logError } from './log';
const SCRIPT_RUNTIME_LIMIT = parseInt(env.SCRIPT_RUNTIME_LIMIT) || 0;
const API_REQUEST_RETRY_LIMIT_IN_SECS = parseInt(env.API_REQUEST_RETRY_LIMIT_IN_SECS) || 0;
const MAX_WAIT_BEFORE_RETRY = 32;
const FETCH_USER_AGENT = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:130.0) Gecko/20100101 Firefox/130.0';

let API_REQUEST_EXTRA_HEADERS = {};
try {
Expand Down Expand Up @@ -186,7 +187,11 @@ export function fetchAll(requests: MatomoRequestParams[], options: ApiFetchOptio

const urlsToFetch = Object.keys(allUrlsMappedToIndex).map((u) => (<URLFetchRequest>{
url: baseUrl,
headers: { ...API_REQUEST_EXTRA_HEADERS, ...authHeaders },
headers: {
'User-Agent': FETCH_USER_AGENT,
...API_REQUEST_EXTRA_HEADERS,
...authHeaders,
},
method: 'post',
payload: u + '&token_auth=' + token,
muteHttpExceptions: true,
Expand Down

0 comments on commit 9e78885

Please sign in to comment.