Collecting data with Trackers and Webhooks

  1. Home
  2. Docs
  3. Collecting data with Trackers and Webhooks
  4. Trackers – collecting data from your own applications
  5. Javascript Tracker
  6. Self Hosting the JavaScript Tracker on Google Cloud

Self Hosting the JavaScript Tracker on Google Cloud

Download the JavaScript tracker file

Navigate to https://github.com/snowplow/snowplow-javascript-tracker/releases and download the latest version of the Snowplow JavaScript Tracker sp.js file

gzip and rename the file (recommended)

Two optional steps you can take are to:

  • rename sp.js to a random 8 character string to reduce the chance of AdBlockers preventing the script from loading e.g. gh7rnghq.js
  • gzip the file to reduce the file size and reduce associated cloud storage and egress costs.

From a terminal / command prompt window, navigate to where you have downloaded the file and gzip -c sp.js > gh7rnghq.js (on Windows you may need to download the gzip binaries)

Uploading to Google Cloud Storage

Create a storage bucket

  1. Navigate to Google Cloud Console and ensure you are in the Google Cloud Project that you wish to host the Snowplow JavaScript Tracker in
  2. Navigate to the Storage section of Google Cloud Console
  3. Create a new bucket with the following settings
Name (also see Connecting your domain to your storage bucket)For example, [company-name]-sp-js
Storage regionSelect a suitable region, multi-region offers the widest availability and highest SLAs
Storage classStandard
Access control optionsFine grained

Connecting your domain to your storage bucket (optional)

You may wish to connect your domain to your Cloud Storage bucket. In this case your bucket can be named in the format of a subdomain e.g.spassets.acme.com.

See Connecting your domain to your storage bucket for additional step you’ll need to take.

Upload your file

Click Upload Files and upload your tracker file.

Make future upgrades easier

We recommend that you create a folder for each version of the JavaScript tracker to make future updates easier. If you wish to do this then first create a folder corresponding to the version and place your tracker file in that folder.

Set metadata

Open the Edit Metadata popup using the file menu.

  1. If you gzipped your file, alter the Content-Encoding value to be gzip
  2. Alter the Cache-Control to max-age=31536000
  3. Save the meta data

Set permissions

Open the Edit Permissions popup using the file menu.

Add a new item in the table, enter the following details and click Save.

EntityGroup
NameallUsers
AccessReader

Click the link icon next to Public to internet to get the file URL e.g. https://storage.googleapis.com/company-name-sp-js/gh7rnghq.js 

Add DNS Record for bucket (optional)

This will only work correctly if:

To connect your domain to your Cloud Storage bucket, you will need to create a CNAME record as below:

Name[your domain]
TypeCNAME
Datac.storage.googleapis.com.

CNAME redirection only works on HTTP, to ensure this works on HTTPS you must follow this troubleshooting guide.

Update your tracking tags

Update any existing tracking tags to point to your self-hosted file URL.