<commit_before>GoogleAnalytics = {};

const GAPI = require("gapitoken");
const GAnalytics = require('googleanalytics');

var gapi = new GAPI({
  iss: Meteor.settings.private.GoogleAnalytics.emailAddress,
  key: Meteor.settings.private.GoogleAnalytics.privateKey,
  scope: "https://www.googleapis.com/auth/analytics",
}, function() {
  gapi.getToken(function(err, token) {
    console.log("Google Analytics token: " + token);

    if (err) {
      console.log(err);
    } else {
      GoogleAnalytics = new GAnalytics.GA({ token });
    }
  });
});<commit_msg>Poll for new Google APIs token every 45 minutes on the server<commit_after>GoogleAnalytics = {};

const GAPI = require("gapitoken");
const GAnalytics = require('googleanalytics');
let pollToken;

var gapi = new GAPI({
  iss: Meteor.settings.private.GoogleAnalytics.emailAddress,
  key: Meteor.settings.private.GoogleAnalytics.privateKey,
  scope: "https://www.googleapis.com/auth/analytics",
}, function() {
  // Set GAPI token
  getGAPIToken();

  // Refresh the GAPI token every 45 minutes
  pollToken = setInterval(getGAPIToken, 60000 * 45);
});

const getGAPIToken = () => {
  gapi.getToken(function(err, token) {
    console.log("Refreshed Google Analytics token: " + token);

    if (err) {
      console.log(err);
    } else {
      GoogleAnalytics = new GAnalytics.GA({ token });
    }
  });
};
{'fraction_non_alphanumeric': 0.14401175606171931, 'fraction_numerical': 0.008082292432035268, 'mean_word_length': 4.025830258302583, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6264825', 'n_tokens_mistral': 461, 'n_tokens_neox': 436, 'n_words': 95}