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

tracking code position #8

Open
ljcljc opened this issue Sep 22, 2016 · 4 comments
Open

tracking code position #8

ljcljc opened this issue Sep 22, 2016 · 4 comments

Comments

@ljcljc
Copy link

ljcljc commented Sep 22, 2016

I want to get my piwik url from contants defined in angular. Can I put the piwik tracking code inside a controller or app.js config?

@inolasco
Copy link
Contributor

inolasco commented Sep 22, 2016

I don't think you can, at the very least not easily and/or without potential side effects. angulartics and the piwik plugin are just a wrapper around the default piwik tracking code, which requires the piwik settings to be defined in a specific way, i.e, as script tags in the HTML. Doing it otherwise would go outside the scope of this plugin, which is to provide easy access and automation to the tracking API. I don't think there's enough benefit in attempting to set the piwik config in angular to merit the effort, specially if the API or code for the config in piwik were to change in the future. The way it is now you can just copy paste it from piwik.

But, if you use PHP or any template language like jade to generate the HTML, you can easily use config variables in the backend for the piwik URL and site ID. That's what I do and in my opinion is a cleaner approach that works well, specially if you have multiple environments, the client shouldn't need to know about them.

@ljcljc
Copy link
Author

ljcljc commented Sep 23, 2016

I do have multiple environments and I don't want to track code to work in development mode. I will try to figure out another way, like using gulp to add piwik code into html tag.

@Disane87
Copy link

@ljcljc then build a condition where to track or not

@WuglyakBolgoink
Copy link

@ljcljc I do so in gulp task:

...
     var id = ((TIER === 'DEV') || (TIER === 'INTEG')) ? 'INTEG' : 'PROD',
            piwikContent = readFileAsync('./configs/templates/piwik-' + id + '.html');

        htmlReplaceConfig.piwik = {
            src: null,
            tpl: piwikContent || ''
        };

        return gulp.src(srcConfig.src.html)
            .pipe(plugins.if(DEBUG, plugins.debug({title: 'BUILD:HTML'})))
            .pipe(plugins.plumber(gulpConfig.plumber))
            .pipe(plugins.htmlReplace(htmlReplaceConfig, {
                keepUnassigned: true
            }))
            .pipe(plugins.htmlmin(gulpConfig.htmlMin))
            .pipe(gulp.dest(srcConfig.dest.html))
            .pipe(plugins.if(DEBUG, reload(gulpConfig.reload)));
...

in piwik-' + id + '.html I have Piwik-settings or empty file, if no need analytic :)

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

4 participants