Installation For Single Page Applications

If your web app is running on a Single Page Application framework, such as Angular or React, and is characterized by very few page refreshes, then installing Zata will be slightly different.

Normally, Zata would depend on page reloads (refresh) to update and trigger new Experiences.

Since Single Page Applications do not reload after URL changes, you must call zata.reload() after each URL change. This is typically done in your application’s router and is handled after a successful page (URL) change.

Here is what we recommend you do.

1. Adding Script and Capturing Properties and Events

First, include the Zata script in your HTML code before the closing </body> tag as you normally would.

For React apps:

<script>
  window.zataProductConfig = {
    secret: "appsecret"
  };
</script>
<script src="https://app.zata.io/js/zata-embed.js"></script>
<script>
  zataProduct.identify( 
    "UNIQUE USER ID", // Used to identify users 
    { 
         name: "John Doe", // Full name 
         email: "customer@example.com", // Email address 
         created_at: "1519205055" // Signup date as a Unix timestamp 
        // Additional user properties 
        // projectId: "1"
        // trialEnds: '2019-10-31T09:29:33.401Z'
    }     
  );
</script>

For Angular apps:

IMPORTANT: If you are copy pasting the above example code, then don't forget to fill in the "App Secret" with your own app token.

You must also pass the "UNIQUE USER ID" to help Zata identify each user.

2. Handling Page Reloads

Next, you must call zataProduct.reload() after each URL change. This is typically done in your application’s router and is handled after a successful page (URL) change.

For example, in a React app it would look something like this:

And on an Angular app, it would look something like this:

3. Handling Change in User Properties Without Page Refresh

IMPORTANT: If your user's data changes in some way without a page load, you should call the zataProduct.identify() function.

This will cause Zata to check for any new changes to the user's data. You only need to include whatever has changed—you don't need to include all user data in each update.

Last updated

Was this helpful?