Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to give Dynamic values to data layer parameters #71

Open
jayakumarim opened this issue Jun 18, 2021 · 0 comments
Open

How to give Dynamic values to data layer parameters #71

jayakumarim opened this issue Jun 18, 2021 · 0 comments

Comments

@jayakumarim
Copy link

jayakumarim commented Jun 18, 2021

Hi All,
I want to give data layer parameters dynamically to each page route in angular.
I add bellow script in tag of index.html.

<script> window.dataLayer = window.dataLayer || []; window.dataLayer.push({ appId: 'UR_REP', pageName: 'test', hostEnv: 'Dev', product: 'OPAY' }); </script>

And i push new values for every page route like below

this.router.events.subscribe(event => {
if (event instanceof NavigationEnd) {
ga('set', 'page', event.urlAfterRedirects);
ga('send', 'pageview');
const currentDataLayer = {
appId: 'UR_REP',
pageName: event.id + '',
hostEnv: 'Dev' + event.id,
product: 'Opay' + event.id
};
window.dataLayer.push(currentDataLayer)
}
});

But it's consider default values for all pages which i gave in index.html.
Please help me how to make in dynamic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant