Page Visits Counter
Pricing
Pay per usage
Go to Apify Store
Page Visits Counter
Counts the current page visits inside an act.
0.0 (0)
Pricing
Pay per usage
2
66
1
Last modified
3 years ago
Pricing
Pay per usage
Counts the current page visits inside an act.
0.0 (0)
Pricing
Pay per usage
2
66
1
Last modified
3 years ago
# This is a template for a Dockerfile used to run acts in Actor system.# The base image name below is set during the act build, based on user settings.# IMPORTANT: The base image must set a correct working directory, such as /usr/src/app or /home/userFROM apify/actor-node-puppeteer-chrome:15-10.1.0
# Second, copy just package.json and package-lock.json since it should be# the only file that affects "npm install" in the next step, to speed up the buildCOPY package*.json ./
# Install NPM packages, skip optional and development dependencies to# keep the image small. Avoid logging too much and print the dependency# tree for debuggingRUN npm --quiet set progress=false \ && npm install --only=prod --no-optional \ && echo "Installed NPM packages:" \ && (npm list --all || true) \ && echo "Node.js version:" \ && node --version \ && echo "NPM version:" \ && npm --version
# Copy source code to container# Do this in the last step, to have fast build if only the source code changedCOPY . ./
# NOTE: The CMD is already defined by the base image.# Uncomment this for local node inspector debugging:# CMD [ "node", "--inspect=0.0.0.0:9229", "main.js" ]
1const Apify = require('apify');2
3const { log } = console;4
5Apify.main(async () => {6 const input = await Apify.getValue('INPUT');7
8 const { client } = Apify;9 const { keyValueStores } = client;10 const {11 count, limit, actName, email12 } = input;13 if (!count || !limit || !actName || !email) {14 throw new Error('Missing input value.');15 }16 const { id: storeId } = await keyValueStores.getOrCreateStore({17 storeName: actName18 });19 client.setOptions({ storeId });20
21 const record = await keyValueStores.getRecord({ key: 'STATE' });22
23 const storeRecord = record && record.body ? record.body : {};24
25 const previousState = typeof storeRecord === 'string' ?26 JSON.parse(storeRecord) : storeRecord;27 log('Previous STATE:', previousState);28
29 const currentCount = Number(count) || 0;30 const previousCount = Number(previousState.count) || 0;31 const nextCount = previousCount + currentCount;32
33 if (nextCount > Number(limit)) {34 const text = `35 The ${actName} has reached its current page visits limit.36
37 Current limit: ${limit},38 Current count: ${nextCount}39
40 Please notify the user to updgrade its current plan!41 `;42 log('Sending notification email...');43 await Apify.call('apify/send-mail', {44 to: email,45 subject: `The ${actName} act has reached its limit!`,46 text47 });48 }49
50 const nextState = Object.assign({}, { count: nextCount, limit });51 log('Next STATE:', nextState);52
53 await keyValueStores.putRecord({54 key: 'STATE',55 body: JSON.stringify(nextState)56 });57});
{ "name": "apify-project", "version": "0.0.1", "description": "", "author": "It's not you it's me", "license": "ISC", "dependencies": { "apify": "0.16.0", "underscore": "latest" }, "scripts": { "start": "node main.js" }}