Skip to main content

Hello,

I am getting duplicate page events when navigating on my wordpress website (doesn’t happen on page load). Interestingly these events seem to come from separate libraries

amplitude-ts-sdk-script/2.11.12
amplitude-ts-script/2.11.12


I am managing my own session_id, device_id and user_id internally, but I want to use Amplitude to help with tracking events. 

Here is my code:

// Create and load the Amplitude script
var s = document.createElement("script");
s.src = "https://cdn.amplitude.com/script/API_KEY.js";
s.async = true;
s.onload = function() {
// Once the script is loaded, initialize Amplitude:
window.amplitude.init('API_KEY', {
fetchRemoteConfig: true,
autocapture: true,
sessionId: 'MY_INTERAL_SESSION_ID'
});
console.log("Amplitude loaded and initialized.");
};
document.head.appendChild(s);

 

On inital load, I get one page event. On subsequent refresh or navigation I get two page events. 

When I split the code up and run in the console, 1) create and load the amplitue script → This triggers a new page

2) Initialise Amplitude → This sends a second page event. I would remove this but as I am tracking my own sessions, I need to add the session_id here.

How can I Implement using my own session and device id and only get one page event per page load. 

I’m running into the same issue - when I load the SDK from our script 

<script src="https://cdn.amplitude.com/script/AMPLITUDE_ID.js"></script>

We are initializing it using the same ID

 

                    window.amplitude.init(data.amplitudeKey, {
fetchRemoteConfig: false,
autocapture: {
attribution: true,
pageViews: false,
sessions: false,
formInteractions: false,
fileDownloads: false,
elementInteractions: false,
},
})

But we are still getting 2 events being fired when we have visits to our page - one that we are calling ourselves, and one from the defaultTracking/page view from Amplitude. interestingly they are both from 2 different sources as well, the same ones mentioned in the original post

amplitude-ts-sdk-script/2.11.12
amplitude-ts-script/2.11.12