# 1. Gravity Field Script

### 1. Implementing preconnect, prefetch & core.js scripts

On every site page in the `<head>` section:

```jsx
<link rel="preconnect" href="//cdn-01.gravityfield.ai">
<link rel="preconnect" href="//evs-01.gravityfield.ai">
<link rel="dns-prefetch" href="//cdn-01.gravityfield.ai">
<link rel="dns-prefetch" href="//evs-01.gravityfield.ai">
```

Additionally, on every site page in the `<head>` section core.js script must be implemented:

```jsx
<script type="text/javascript" src="//cdn-01.gravityfield.ai/core/core.js"></script>
```

### 2. Implementing GF, Section ID, Page Context variables

Each page must declare a GF variable. It is declared within a separate script consisting of three parts:

```javascript
<script>
window.GF = window.GF || {}; 
GF.section = "111aaa222bbb"; // Section ID, string
GF.pageContext = { type: "PAGETYPE", data: [] }; // PAGETYPE and an empty array just as an example
</script>
```

1. GF variable itself;
2. `GF.section` - unique section ID which must be of **string** type;
3. `GF.pageContext` - variable passing the information about the page context and its description. In the Page Context you can  pass a localization parameter `lng`. You can use `lng` in the case that your site/app is available in more than one language/region and personalization campaigns need to adjust content according to the language/region. You can also use this parameter if there are different product attributes (price/discount amount, etc) in different regions/cities.\
   More about page context: [2. Page Context](/lang/en/implementation/client-side-integration/2.-page-context.md)

More about scripts: [Gravity Field Scripts Workflow](/lang/en/implementation/client-side-integration/1.-gravity-field-script/scripts.md)

## Appendix

Example of correctly installed scripts on the shopping cart page:

{% code overflow="wrap" %}

```javascript
<link rel="preconnect" href="//cdn-01.gravityfield.ai">
<link rel="preconnect" href="//evs-01.gravityfield.ai">
<link rel="dns-prefetch" href="//cdn-01.gravityfield.ai">
<link rel="dns-prefetch" href="//evs-01.gravityfield.ai">

<script>
window.GF = window.GF || {}; 
GF.section = "6315dda2f1c33ba4cd04655b";
GF.pageContext = {type: "CART",data: ["XD-154","DL-5874","TN-15","QSD-1581","XD-15"]};
</script>

<script type="text/javascript" src="//cdn-01.gravityfield.ai/core/core.js"></script>
```

{% endcode %}

Script connection order:

1. Preconnect and prefetch;
2. Declaring the GF variable and specifying a Page Context;
3. Core.js.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.gravityfield.ai/lang/en/implementation/client-side-integration/1.-gravity-field-script.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
