Issue with tracking code and SPA - Tracking code only loads and scan first loaded page

Hi,

I have an issue (aka my biggest nightmare) with the tracking code installed in a SAP built in Angular with collected forms

The main problem is that the tracking code is properly tracking the first “page” load. However, it does not rescan a page to look for a form if the user moves around on the site before hitting the form page. In this case, nothing is sent from the form to hubspot (in this case to create a contact). I would use the Contacts API, but then all the ads analitycs are lost, since it sets the “original source” field to “Offline Source” and it doesnt even recognise that a form has been submited.

Is there a way to force the HubSpot script to rescan for a form each time the component content loads? This is driving me crazy.

Thanks a lot in advance!

Hi @itur

Thank you for reaching out.

I want to tag some of our experts on this - @tjoyce @thesnappingdog @MatthewShepherd do you have suggestions for @itur on this?

Thank you!

Best

Tiphaine

Hi @itur -

You should be able tap into your router for angular and update the tracking events yourself

 _hsq.push(['setPath', '/what-we-do']);
 _hsq.push(['trackPageView']);
 import { Component, OnInit } from '@angular/core';
 import { Router, NavigationEnd } from '@angular/router';
 import { filter } from 'rxjs/operators';

 @Component({
 selector: 'app-my-class',
 templateUrl: './my-class.component.html',
 styleUrls: ['./my-class.component.scss']
 })
 export class MyClassComponent implements OnInit {
 constructor(private router: Router) {}

 ngOnInit(): void {
 this.router.events
 .pipe(filter(event => event instanceof NavigationEnd)) 
 .subscribe((event: NavigationEnd) => {
 _hsq.push(['setPath', '/what-we-do']);
 _hsq.push(['trackPageView']);
 });
 }
 }

Thank you so much! That was really helpfull :blush: