Skip to content

Sample React SPA using the Kentico Cloud Delivery API to fetch content.

License

Notifications You must be signed in to change notification settings

Enngage/cloud-sample-app-js

 
 

Repository files navigation

Kentico Cloud sample React single-page application

Build Status Live Demo Forums

This is a sample website written in JavaScript utilizing the Kentico Cloud Delivery API to manage and retrieve content. You can register your account for free at https://app.kenticocloud.com.

Application setup

  1. Install the latest version of NodeJS and npm. You can download both at https://nodejs.org/en/download/.
  2. Clone the sample application repository.
  3. Navigate to the root folder of the application in the command line.
  4. Type npm install to install required npm packages.
  5. Type npm start to start a development server.
  6. The application opens in your browser at http://localhost:3000.

After starting, the sample application retrieves content from the default Kentico Cloud sample project.

Connecting your project

If you want to change the source Kentico Cloud project, follow these steps:

  1. In Kentico Cloud, choose Project settings from the app menu.
  2. Under Development, choose API keys.
  3. Copy your Project ID
  4. Open the src\Client.js file in the sample application folder.
  5. Find the projectId constant.
  6. Change the values of the constant using the Project ID key you copied.
  7. Save the file.

When you now run the sample application, the application retrieves content from your project.

Get creative

Deploy, explore and change the app directly in the browser.

Remix on Glitch

Previewing content from your project

If you already have a Kentico Cloud account and you want to connect the sample application to a project of your own, you need to provide your Project ID and your Preview API key to authorize requests to the Delivery Preview API. For example, you can connect the application to your modified version of the sample project.

To preview content in the sample application, follow these steps:

  1. In Kentico Cloud, choose Project settings from the app menu.
  2. Under Development, choose API keys.
  3. Copy your Project ID and Preview API key.
  4. Open the src\Client.js file in the sample application folder.
  5. Find the projectId and previewApiKey constants.
  6. Change the values of the constants using the Project ID and Preview API key you copied.
  7. Save the file.

When you now run the application, you will see all project content including the unpublished version of content items.

Content administration

  1. Navigate to https://app.kenticocloud.com in your browser.
  2. Sign in with your credentials.
  3. Manage content in the content administration interface of your sample project.

You can learn more about content editing with Kentico Cloud in the documentation.

Content delivery

You can retrieve content either through the Kentico Cloud Delivery SDKs or the Kentico Cloud Delivery API:

  • For published content, use https://deliver.kenticocloud.com/PROJECT_ID/items.
  • For unpublished content, use https://preview-deliver.kenticocloud.com/PROJECT_ID/items.

For more info about the API, see the API reference.

You can find the Delivery and other SDKs at https://github.com/Kentico.

Tracking visitors and their activity

By default you can see sample visitor data in Kentico Cloud, even if you already feed the single-page application with your own content. Tracking real visitors needs to be set up separately and here's how to.

In single-page applications you have to use custom activities to track visitor activity. This is how you set up tracking visits of About Us page:

  1. In Kentico Cloud, choose Project settings from the app menu.
  2. Under Development, choose API keys.
  3. Copy your Project ID.
  4. Open the public\index.html file in the sample application folder.
  5. Find function call ket('start', ''); and use your Project ID as its second parameter.
  6. Save the file.
  7. Go back to your Project settings in Kentico Cloud
  8. Under Development, choose Activity tracking.
  9. Create a new custom activity and copy its codename.
  10. Open the src\Utilities\ActivityLogging.js file in the sample application folder.
  11. Find function call window.ket('action', ''); and use the codename you copied as its second parameter.
  12. Save the file.

When you now run the application and visit the About Us page, you should be able to see your visit in Analytics of Kentico Cloud. You can also create a new dynamic segment of people who did the custom activity you created and see that the segment is not empty. It should contain you as an anonymous visitor. You can learn more about creating segments with Kentico Cloud in the documentation.

Deployment

You can use eg. surge to deploy your app live. Check out the step-by-step guide on our blog.

Wall of Fame

We would like to express our thanks to the following people who contributed and made the project possible:

Would you like to become a hero too? Pick an issue and send us a pull request!

About

Sample React SPA using the Kentico Cloud Delivery API to fetch content.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • CSS 56.9%
  • JavaScript 42.8%
  • HTML 0.3%