# About Extended APIs for Measurement

## Custom Event Configuration setCustomEvent

Function: Each time it is applied, you can transfer the number of events and measure behavioral data such as button clicks, registration completion, and adding to shopping cart. You can set it based on the logic required for your business and obtain data. For example, when measuring the number of registrations, place the custom event code in the AJAX success function and proceed with measurement.

**Format:**

```
_pt_sp_2.push('setCustomEvent',{ eventName:'Event Name', isActiveElement:Interactive Element})
```

Parameter eventName: Event name, String type, required selection from fixed strings. Parameter isActiveElement: Whether it is an interactive element, Number, optional, 1: Interactive element, 0: Non-interactive element. Default value is 0.

**Example:**

```
_pt_sp_2.push('setCustomEvent',{ 
    eventName:'Manual Event Tracking', 
    isActiveElement:1
})
```

## Custom Dimension setCustomVar

**Format:**

```
_pt_sp_2.push('setCustomVarV2',{eventName: 'Event-based Custom Variable'}) 
```

**Function:** In addition to event configuration, you can add custom variables through code. For example, for an event such as "Add to shopping cart", you can measure product type and product price. The corresponding variables would be "Product type added to shopping cart" and "Product price added to shopping cart" respectively. This feature can be used by subscribing to a special plan or by integrating with DataDeck.

**Parameters:** setCustomVarV2 is a fixed value, so you must select it. The second parameter becomes a JSON format object. The second parameter {key: value}: You can add up to 10 key: value pairs to collect data. The diagram shows 4 configured, and 6 more can be configured.

**Key (Property Name):** Use a combination of numbers, letters, and underscores. If other characters are used, data will not be collected. Also, data cannot be collected if the key is 12 characters or longer. Additionally, if duplicate keys are added, they will be overwritten by the duplicate key.

**Value (Property Value):** Data type: There are 4 types: string, int, float, and date. If data types other than these are used, data will not be collected. The length limits for various data types are as follows.

**String (string):** Data with 50 characters or more will not be collected.

**Integer (int):** (-2147483648, 2147483647), data will not be collected if integers outside this range are used.

**Float (float):** (-4294967296, 4294967294), data will not be collected if floating-point numbers outside this range are used.

**Date (date):** The time format must be "YYYY-MM-DD HH:MM:SS". If the format is incorrect, data will not be collected.

**Example:**

```
_pt_sp_2.push('setCustomVarV2',{
    eventName: 'Purchase',
    productId: 123456,
    productCatalog: 'Product Category',
    productName: 'Product Name',
    productPrice: 123.45,
    createDate: '2018-04-23 15:40:46'
})
```

## Cross-Domain Configuration setCrossDomainLink

**Format:**

```
_pt_sp_2.push('setCrossDomainLink,allManual/halfManual'); 
```

**Function:** Cross-domain configuration linking. Even if the same tracking code is placed on domain A and domain B, when a user moves from domain A to domain B, cookies cannot be shared, so visit counts are separated and correct data collection is hindered. To link visits, you can use this feature to match visits. The principle of this API is to take cookie information and use it as linking point information in the href tag attribute to collect the system's visit data. If the movement from the website is not done via the `a` tag href method, this feature cannot be used.

**Parameters:** allManual becomes fully manual mode. Add the `onclick="pt_domain"` attribute inside the `a` tag that requires cross-domain processing. If the user has already set an onclick event (for example: `onclick="test()"`), you can add pt\_domain at the very end (for example: `onclick="test();pt_domain"`). If the `a` tag does not have this attribute, cross-domain processing will not be performed.

halfManual is semi-manual mode. Even without modifying the `a` tag, cross-domain processing is applied to all `a` tags in the page.

## Set Page Title setVPT

**Format:**

```
_pt_sp_2.push('setVPT,Demo Title'); 
```

**Function:** Set the demo title. If the page does not have a title tag, it will be displayed as "not set" in Ptengine. To avoid this situation, you can use this feature to manually set the page title.

**Example:**

```
_pt_sp_2.push('setVPT,ptmind'); 
```

Original page title: ptengine After using setVPT, the title visible in Ptengine: ptmind

## setVPV

**Format:**

```
_pt_sp_2.push('setVPV,Demo URL');
```

**Function:** You can set the demo URL. Note: When using this feature, URLs are automatically converted to lowercase, so if the URL contains uppercase letters, it may be affected.

Example:

```
_pt_sp_2.push('setVPV,http://www.baidu.com/your'); 
```

Original URL: `http://www.baidu.com` After setVPV: `http://www.baidu.com/your`

## setURL

**Format:** `_pt_sp_2.push('setURL,#');`

**Function:** Set the information after the "#" in the URL.

**Example:**

```
_pt_sp_2.push('setURL,btnSave'); 
```

Original URL: `http://www.baidu.com`

URL displayed in Ptengine after using setURL: `http://www.baidu.com#btnSave`

## setPVTag

**Format:**

```
_pt_sp_2.push('setPVTag,URL/#Location Information,replace'); 
```

**Function:** This is a feature to send PV data once. It allows URL changes on websites built with single-page applications to be converted into demo PV. If the page has not actually moved but the URL and page content have changed, using this function will generate a demo URL, and all subsequent data can be attributed to the new URL.

**Parameter 1:** If parameter 2 (replace) is not set, this value is similar to the # location information that needs to be added to the original URL. The generated demo URL is (original URL + # location information).

When parameter 2 is set to replace, this value becomes the complete URL after the change. The generated demo URL becomes the new URL newly set by this value.

**Parameter 2:** replace

**Example 1:** Original URL: `http://www.ptmind.com` Demo URL to generate: `http://www.ptmind.com#login` In this case, the following function is needed:

```
_pt_sp_2.push('setPVTag,login');
```

**Example 2:** Original URL: `http://www.ptmind.com` Demo URL to generate: `http://www.ptmind.com/login`

In this case, the following function is needed:

```
_pt_sp_2.push('setPVTag,http://www.ptmind.com/login,replace');
```

## Sample Rate Configuration setSampleRate

**Format:**

```
_pt_sp_2.push('setSampleRate,Sample Rate'); 
```

**Function:** Set the sample rate for collected data. If website visit data is too large and you do not want to collect the full amount, you can control data measurement by setting a sample rate.

**Parameter 1:** Sample rate setting, required selection. Example: If set to 1000, the displayed sample rate will be 1/1000, and only 10 UU visits will be collected out of 10,000 UU.

Example:

```
<script>
window._pt_sp_2 = window._pt_sp_2 || [];
_pt_sp_2.push('setSampleRate,1000');
_pt_sp_2.push('setAccount,sid')
</script>
<script src="https://js.ptengine.jp/sid.js"></script>
```

## Prevent New Visits from Ad Parameters setIgnoreCampaign

**Format:**

```
_pt_sp_2.push('setIgnoreCampaign,true'); 
```

**Function:** Because the data collection system automatically displays pages containing ad parameters as the entry page for new visits, even if you repeatedly reload, each reload will be counted as the entry page for a new visit.

**Parameter:** If this value is true, ad (utm) parameters are ignored and new visits are not created by ad parameters. If false, ad (utm) parameters are not ignored, and each visit is to a page containing ad parameters, so it is counted as a new visit.

## Turn on Event Measurement in iframe setIframe

**Format:**

```
_pt_sp_2.push('setIframe,true'); 
```

**Function:** Enable event measurement inside iframes.

**Parameter:** If this value is true, event measurement in iframes is turned on; if not true, it is not turned on. In the default state, event measurement in iframes is turned off.


---

# 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://helps.ptengine.com/en/developer/extended-api.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.
