Note
See Building and Deploying > Manually to deploy this Managed Component to your Cloudflare account. Then see Tool Settings to configure the component within Zaraz.
- How to deploy a custom Zaraz Managed Component: Custom MC docs
- The managed component assumes you have deployed counterscale on the same Cloudflare Account as your MC and have left the default worker name as
counterscale
. There are no plans to support other worker names or external deployments at this time.
Settings are used to configure the tool in a Component Manager config file
Note
In Zaraz, you will need to manually add the "settings" fields making sure to use the correct field names. See the below screenshot:
siteId
can be practically any string. It is used to identify the site in the Counterscale system. You can find it in the Counterscale dashboard.
apiBaseUrl
is the base URL of the Counterscale API. If you have Counterscale on its own domain it may look like https://stats.example.com/
. If you have Counterscale on a route of your domain it may look like https://example.com/api/counterscale/
. Either way, the URL should point to the Counterscale API with the collect
endpoint.
Fields are properties that can/must be sent with certain events
Note
In Zaraz, you will need to manually add the action field settings making sure to use the correct field names. See the below screenshot:
country
is the country of the visitor. It is used to track the location of the visitor. It is optional and if not provided, the location will not be tracked. The country should be sent in each event action as a custom field called country
. In Zaraz, use the "Country code" property, which passes the user's country code to the action.
- Clone the repo and enter the
mc
directory - Run
npm install
to install dependencies - Run
npm run build
to build the Managed Component - Go back to the root directory by running
cd ..
- Run
npx managed-component-to-cloudflare-worker ./mc/dist/index.js custom-mc-counterscale ./wrangler.toml
to package and deploy the worker to your Cloudflare account
CI/CD GitHub Actions are set up to automate the build and deploy process. You will need to complete the following steps based on the Workers docs:
- Create an Actions secret called
CLOUDFLARE_API_TOKEN
with a Cloudflare API token that has permission to edit Workers (use theEdit Workers
template) - Create an Actions secret called
CLOUDFLARE_ACCOUNT_ID
with your Cloudflare account ID (easily found here)
- The
mc
directory contains the Zaraz Managed Component code. - To test or deploy, first run
npm run build
in themc
directory, which will create thedist/index.js
used by the packaging script to deploy the Worker to your Cloudflare account using Wrangler.
Licensed under the MIT License.