# Page tracker

{% hint style="danger" %}
You should **not** use this feature if you have "**Enhanced measurement"** turned on in your Data Stream options. Google will also start tracking pageviews, and you will get double hits on the same page.

If you need both features, turn off the "*Page changes based on browser history events*" options in the pageviews advanced settings.
{% endhint %}

If you are using [VueRouter](https://github.com/vuejs/vue-router) inside your application, you can simply pass your router instance, and the plugin will start tracking all your pages automatically

```javascript
import { configure } from "vue-gtag";
import router from './router'

configure({
  tagId: "GA_MEASUREMENT_ID",
  pageTracker: {
    router,
  }
})

```

By default, the tracking system uses pageviews with the following template.

```javascript
{
  page_path: '/', // route path value
  page_location: 'http://localhost:8080/' // window.location.href
}
```

## Enable screen\_view

Now, it will use screen\_view events for tracking instead of the default page

```javascript
import { createGtag } from "vue-gtag";
import router from './router'

configure({
  tagId: "GA_MEASUREMENT_ID",
  pageTracker: {
    router,
    useScreenview: true
  }
})
```

## Page tracker template

The automatic tracker system can use a custom template, instead of the default one: this will apply whether you are using pageviews or screenviews.

```javascript
import { configure } from "vue-gtag";
import router from './router'

configure({
  tagId: "GA_MEASUREMENT_ID",
  pageTracker: {
    router,
    template: (to) => ({
      page_title: 'awesome page',
      page_path: to.path
    })
  }
})
```

## Exclude routes&#x20;

pass routes path or routes name that you want to exclude from the automatic tracking&#x20;

```javascript
import { configure } from "vue-gtag";
import router from './router'

configure({
  tagId: "GA_MEASUREMENT_ID",
  pageTracker: {
    router,
    exclude: ['route_path_value', 'route_name_value']
  }
})
```

You can also provide a custom function that returns a boolean value.

```javascript
import { configure } from "vue-gtag";
import router from './router'

configure({
  tagId: "GA_MEASUREMENT_ID",
  pageTracker: {
    router,
    exclude: (to) => to.name === 'about'
  }
})
```

## Route path types

Use route full path&#x20;

```javascript
import { configure } from "vue-gtag";
import router from './router'

configure({
  tagId: "GA_MEASUREMENT_ID",
  pageTracker: {
    router,
    useRouteFullPath: true
  }
})
```

Prepend router base path

```javascript
import { configure } from "vue-gtag";
import router from './router'

configure({
  tagId: "GA_MEASUREMENT_ID",
  pageTracker: {
    router,
    useRouterBasePath: true
  }
}) 
```


---

# 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://matteo-gabriele.gitbook.io/vue-gtag/page-tracker.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.
